0

Problem with code

I think that the output of the program should be 4 5 6 7 but the output is 5 4 6 7 please explain this? https://code.sololearn.com/cE5S4zkA6g42/?ref=app https://code.sololearn.com/cE5S4zkA6g42/?ref=app

17th Sep 2018, 2:27 PM
Shubh Agrawal
Shubh Agrawal - avatar
3 Réponses
+ 7
You put 4 at the start. You put 5 at the start so 4 is now second. You put 6 at end so it follows 4. You put 7 at end so it follows 6. You should either remove tail or make use of it. If you update it correctly, put at end can lose the loop as tail has the last item of the list.
17th Sep 2018, 3:17 PM
John Wells
John Wells - avatar
+ 5
linkedList a; //empy list a.addNodeAtStart(4); // adds 4 list -> 4 a.addNodeAtStart(5); // adds 5 to start list -> 5, 4 a.addNodeAtEnd(6); // adds 6 to end list -> 5, 4, 6 a.addNodeAtEnd(7); // adds 7 to end list -> 5, 4, 6, 7 a.display();
17th Sep 2018, 3:15 PM
Mert Yazıcı
Mert Yazıcı - avatar
+ 2
Thanks .. i messed up the logic
17th Sep 2018, 3:26 PM
Shubh Agrawal
Shubh Agrawal - avatar