Basic Data Structures Comments

Comments

  • Hi, how can I complete this first point in list ? it's always incomplete :)

  • Yes, same here.

  • I don't understand the class definition. What does the line

    Node next;

    mean?

  • Node is the name of the class (like Car or String). Each Node points to another Node called 'next' (though it could be called anything else as well).

  • Thanks. I'll think about that...

  • In JavaScript we can implement a Node as follows (highly similar in form as the one in the lesson):

    class Node {
    constructor(data){
    this.data = data;

    cont...
  • A better implementation of the Node class.
    class Node
    {
    private E element;
    private Node next;
    public Node(E element, Node next)

    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?

  • 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.

  • Hello guys, I'm using the java.util.LinkedList implementation and it doesn't give the 'correct' output you are putting here, my implementation of LinkedList does the same output as java.util.LinkedList, are you sure the 'correct' output is correct at all? Thanks for this nice web page.

  • Your code needs to handle the different input formats correctly. There are 2 new formats for this challenge: -1 n should remove a number at index n, and 2 positive numbers a b means insert b at index a.

  • Is there a featured awnser here. I would really like to be able to see the awnsers. I only get nullpointexceptions. How can i see the featered awnser if there is one, before i solve this. cause i dont think i can solve this.

  • my code

    Really what am i doing wrong?? It says main.java54 nullpointer but rule 54 is the same as in the previous excersise. Can i just get the awnser please.

  • 54 means the error happened at line 54 in your code. Go there to fix it. nullpointer means you tried doing something with a null value.

  • Yes, i now rule/line 54 but here was nothing wrong there. it was the same as in the previous excersice strange but i had some help already thank you.

  • 10th step is supposed to remove the number 5 which will be in 2th position. Not sure how will it get printed after 14. I get the out pust as 3
    11
    14
    7
    7
    10
    3
    2

  • @senthil, you might want to read again the requirement/instruction for the remove(index) method, the answer to your question is in there.

  • I got the correct output and a correct check. But also an error message, i dont know if that is importent i just mention it.

    Note: /usercode/Main.java uses unchecked or unsafe operations.
    Note: Recompile with -Xlint:unchecked for details.

    my code

  • That looks like it has to do with the way you used a Java stack.

  • Please send me the code

  • I think you are supposed to implement the LinkedList to solve your problem ansd not the built-in Stack module

  • It says correct but also gives a weird error. I dont know what it is?
    I just mention it: Note: /usercode/Main.java uses unchecked or unsafe operations.
    Note: Recompile with -Xlint:unchecked for details.

    a solution my code

  • @thales Adik yalaaa :D

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