• Post Reply Bookmark Topic Watch Topic
  • New Topic

problem traversing LinkedList  RSS feed

 
Adam Chalkley
Ranch Hand
Posts: 518
4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys I am having a problem traversing my linkedList,when I traverse  it forwards it works but when I do it backwards I get stuck in an infinite loop that just keeps print out 1 or the first Nodes data value

can anyone tell me where I have gone wrong in my code?

thanks

 
Adam Chalkley
Ranch Hand
Posts: 518
4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
********** SORRY POSTED WRONG CODE*************

here is actual code


 
Adam Chalkley
Ranch Hand
Posts: 518
4
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys I figured out what was wrong

I set the head = to the newly created Node then I checked to see if head != null which it did not,so then I set head.previous = new Node which is the same node keeping me in an infinite loop,I should have declared head = newNode after the if statement to avoid the loop.
 
Campbell Ritchie
Marshal
Posts: 56578
172
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well done sorting it out and telling us the answer.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!