Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

A challenge

 
Remo Fernandez
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I hav a linkedlist problom.i hav tried a lot to resolve it.but i cant.
this linked list allowing new elements to be added to the front and deleted from the front.how can it be modified so that it adds elements to the end of the list rather than the front of the list?.
that means,
when i run this program,if i input 3 Strings as "aa","bb","cc",the current output will be,
cc
aa
bb
i want to change the program so it prints,
aa
bb
cc
it can be done by adding elements to the end of the list rather than the front of the list.anyone can do it??.here's the hint.
HINT one way is to store a Reference to the last element of the list and use it to access the end of the list. The other way is to traverse from the front to the last node in a similar way to traverse, then once there create a new node and put a reference to it from the last node. You will also need to be careful about the case when you are adding to an empty list.
 
Julie Hay
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is this homework or something you are doing in your spare time just curious? it seems you need to turn you linked list into a double linked list. Each node should have a message, nextNode, and previousNode. Plus a refrence to the last node, and another method to print using previousNode and not nextNode.
 
Jessica Sant
Sheriff
Posts: 4313
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
moving this to Java in General (Intermediate) seeing as though you're trying to create your own linked list and play with it rather than asking questions about the java.util.LinkedList class that you'd be tested on in the Certification exam.
Please continue the conversation there.
 
Billybob Marshall
Ranch Hand
Posts: 202
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jessica, while I know why you zapped my (flame) response, it's ironic that you wouldn't instead just zap this whole obvious homework thread, which he/she posted in 4 separate forums (so far)
[ February 19, 2004: Message edited by: Billybob Marshall ]
 
Jessica Sant
Sheriff
Posts: 4313
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Billybob-
I didn't zap any of your posts -- someone else must have. I didn't realize this had been posted in muultiple forums, thanks for letting me know.
Remo-
Please don't post the same question in multiple forums, it wastes people's times and makes the conversation difficult to follow.
As for your homework. Here at the Javaranch, we're more than happy to help you with any specific questions you have, but we won't do your homework for you. That you need to do on your own.
Please continue the conversation in the original thread here.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic