Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: Nodes

  1. #1
    Junior Member
    Join Date
    Nov 2012
    Posts
    26
    Thanks
    3
    Thanked 1 Time in 1 Post

    Default Nodes

    So I absolutely cannot figure out nodes. I have no clue what I am doing. I can't figure out how to do the add method. So far all I have is:


    public class List{
     
        Node head = null; //the start of the linked list
        private 
     
        public void add(Object next, int index){
            if(head == null){ //adding to an empty list (changes head)
                head = new Node(next, head);     //what about index?
            }else if( ){ //adding to a single element list (changes head)
     
            }else if(){ //adding to a populated list (n>=2)
                Node temp = head;
                while(temp.next != null){
                    temp = temp.next;
                }
                temp.next = new Node(next, index) //not correct.....
            }
     
        }
    }


  2. #2
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Re: Nodes

    Where is the algorithm you are trying to write code to? or did you skip that part?

  3. #3
    Grand Poobah
    Join Date
    Mar 2011
    Posts
    1,545
    My Mood
    Grumpy
    Thanks
    0
    Thanked 167 Times in 158 Posts

    Default Re: Nodes

    What constructors does the Node class have?
    Improving the world one idiot at a time!

Similar Threads

  1. Linked Lists and Nodes
    By tomlisi92 in forum What's Wrong With My Code?
    Replies: 5
    Last Post: March 22nd, 2013, 05:07 AM
  2. [SOLVED] All the paths between 2 nodes in a graph
    By Alhazred in forum Algorithms & Recursion
    Replies: 6
    Last Post: May 15th, 2012, 07:49 AM
  3. where to put the nodes into the array?
    By blaster in forum Algorithms & Recursion
    Replies: 9
    Last Post: March 11th, 2012, 07:03 PM
  4. JTree - Remove All Nodes
    By aussiemcgr in forum Java Theory & Questions
    Replies: 4
    Last Post: December 9th, 2010, 05:27 PM
  5. Having trouble redirecting nodes
    By KingLane in forum Collections and Generics
    Replies: 6
    Last Post: October 19th, 2009, 06:46 PM

Tags for this Thread