Results 1 to 2 of 2
Thread: Sorted Doubly linked List
- 10-14-2010, 08:29 AM #1
Member
- Join Date
- Oct 2010
- Posts
- 1
- Rep Power
- 0
Sorted Doubly linked List
I required to create a sorted doubly linked list for my homework. Inside the SortedStringList, I need to implement a method called insert(). I have some problem in doing so. I don't what is going wrong to my code below:
XML Code:public class SortedStringList { private static class Node { public String value; public Node previous, next; public Node(String v, Node p, Node n) { value = v; previous = p; next = n; } } private Node first; private Node last; public SortedStringList(){ this.first = null; this.last = null; } public void insert(String s){ Node newnode = new Node(s,this.first,this.last); if(first == null){ first = newnode; } else if(first.value.compareTo(s) >= 0){ newnode.next = first; newnode.previous = null; first = newnode; last = first; } else { Node current = first; newnode.previous = first; while(current.value.compareTo(s)<=0 ){ if(current.next == null){ current.next = newnode; first = current; last = newnode.next; } first.previous = current; current = current.next; } first.previous.next = newnode; newnode.next = current; current = first; } } }
Can somebody please give me some idea?
- 10-14-2010, 10:05 AM #2
Similar Threads
-
I need Help Using an "AddSorted" method to a Doubly Linked List
By Auxilium in forum Advanced JavaReplies: 12Last Post: 10-10-2010, 11:17 PM -
Doubly Linked List
By matin1234 in forum New To JavaReplies: 0Last Post: 06-02-2010, 05:58 AM -
doubly linked list insert
By ineedhelpwithjava in forum Advanced JavaReplies: 1Last Post: 03-20-2009, 02:05 PM -
Help with Doubly linked list
By Dr Gonzo in forum New To JavaReplies: 5Last Post: 12-06-2008, 07:45 AM -
Doubly-linked list with data structure
By Java Tip in forum java.langReplies: 0Last Post: 04-16-2008, 10:30 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks