Lists Comments

Comments

  • List created by add operation as said in the above post is 3 5 4 7 , I think the list will be 3 5 7 4 and not 3 5 4 7. Please correct me if my understanding is wrong

  • import java.util.Scanner;

    class LinkedList {

    Node head;
    Node tail;
    
    /*
     * Adds Node to end of list with given `num` as data
    
    cont...
  • public void add(int num){
        head = tail;
        tail.next = new Node(num);
        tail = tail.next;
    
    
    
    }
    
    /*
     * Returns value of node at given index
    
    cont...
  • what am i supposed to return?

  • import java.util.Scanner;

    class LinkedList {

    Node head;
    Node tail;
    private Node temp = null;
    
    
    /*
     * Adds Node to end of list with given `num` as data
    
    cont...
  • this is telling me that my return value needs to be an integer, I'm lost

  • @sarah, you can link to long pieces of code so you don't need to paste them here. The method get needs to return an integer (the value or data of a node). See if the new hint helps (or the new cheat option if you need it.)

  • thanks, i realize what i was doing wrong.

  • Do i understand it correct if i say that head and tails arent nodes themselves?

  • No, the first node in the list is the head and the last node is the tail. (If there's just one node, it's both the head and tail.)

  • When i state tail is head , can i consider them as one node with 2 names (startingpoint), or are they two different nodes with the same name. In case two i dont understand the line:

    cont...
  • class LinkedList {
    Node head;
    Node tail;

    So i have two 'dummy' nodes. But what is the data en what is the pointer of head.

    if head==0 -------------> what does this mean, what is null, the pointer? Then what is the data?

  • Nevermind, i understand it now. Its cause the default points to null.

    Also i understand why i can say tail.next and it does the same for the head. This cause its a reference variable. So i guess i figured it out :-)

  • Why is it supposed to be
    head = tail...
    and not
    head.next=tail;

    THis is driving me nuts! I drew this out on paper TWICE and while I understand the concept... I cant code it!

  • Which part are you referring to? When there's only one item in the list, that item is both the head and the tail. This a correct solution.

  • is that python 2.6
    I am using python 3.5 working ok on my ide but here it is failing on
    reading data.

  • Yes it's python 2.

Contact Us
Sign in or email us at [email protected]