Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

ListNode linked list help

807589Oct 2 2008 — edited Oct 3 2008
I am trying to write a LinkedList manually, by connecting listnodes in alphabetical order. however, I can't figure out my add or delete method. I figure once i get add delete will be easy. I know my listnode class works, but I need help with my add method.
front refers to a dummy node.

public void add(String s) {
ListNode c = front;
ListNode holder = front;
ListNode adder = new ListNode(s, null);
if(c.getNext() == null){
front.setNext(adder);
}
else {
while (c.getNext() != null) {
if (adder.getValue().compareTo(c.getValue()) < 0) {
c.setNext(adder);
adder.setNext(holder);
adder.getNext();
c.getNext();

}}
}
}
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 31 2008
Added on Oct 2 2008
4 comments
1,142 views