Welcome to Dream.In.Code
Become a Java Expert!

Join 149,478 Java Programmers for FREE! Get instant access to thousands of Java experts, tutorials, code snippets, and more! There are 1,606 people online right now. Registration is fast and FREE... Join Now!




Double Linked List: stuck on basic stuff

 
Reply to this topicStart new topic

Double Linked List: stuck on basic stuff, please help

system0utprint
19 Apr, 2007 - 06:07 PM
Post #1

New D.I.C Head
*

Joined: 29 Jan, 2007
Posts: 7


My Contributions
Hi,
I'm stuck on a doubly linked list program. I need to find the length of a list, add a node at the beginning, and print the list. Each node stores an integer and a reference, and the list is doubly linked so there's a head as well as a tail. Some node methods are getNext, getPrevious, setNext, setPrevious...
I'm pretty sure I got some logical errors here...

Thank you for any help!

CODE
    public int lengthFinder(){
        int counter = 0;
        Node temp = head;
        while(temp!=null){
        temp = temp.getNext();
        counter++;
        }
    return counter;
    }

    public void addANodeAtBeginning(int newData){
        Node other = new Node(newData, head);
        head = other;
    }

    public void print() {
        Node temp = head;
        while(temp!=null){
        System.out.print(temp.getData() + " ");
        temp = temp.getNext();
        }
        System.out.println();
    }/

User is offlineProfile CardPM
+Quote Post

keems21
RE: Double Linked List: Stuck On Basic Stuff
19 Apr, 2007 - 09:15 PM
Post #2

D.I.C Head
Group Icon

Joined: 3 Feb, 2007
Posts: 183



Thanked: 2 times
Dream Kudos: 25
My Contributions
I can't see anything wrong with your code there. Are you getting errors any errors?
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/7/09 03:45PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live Java Help!

Java Tutorials

Reference Sheets

Java Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month