Hi, I have this *single circular linked list* structure:
> public class ListItem {
> int n;
> ListItem next;
>
> public ListItem() {
> this.n = 0;
> this.next = null;
> }
>
> public ListItem(int n, ListItem e) {
> this.n = n;
> this.next = e;
> }
>
> public int getValue() { return this.n; }
> public ListItem getNext() { return this.next; }
> public void setValue(int n) { this.n = n; }
> public void setNext(ListItem nextItem) { this.next = nextItem; }
> }
public class List {
> ListItem head;
>
> public List() {
> this.head = null;
> }
>
> public ListItem getHead() { return this.head; }
>
> public void Insert(int n) {
> if (this.head == null) {
> this.head = new ListItem(n, null);
> this.head.next = head;
> } else if (this.head.getNext() == null) {
> this.head = new ListItem(n, this.head);
> head.setNext(head);
> } else {
> this.head.next = new ListItem(n, this.head.next);
> }
>
> }
>
> public void Remove(int Key) {
> ListItem curr = this.head;
>
> do {
> if ( curr.next.getValue() == Key ) {
> ListItem temp = curr.getNext();
> curr.setNext(temp.getNext());
> } curr = curr.getNext();
>
> if (curr.getNext() == this.head && curr.getValue() == Key)
> {
> this.head.setNext(null);
> curr.setNext(null);
> }
>
> } while ( curr != this.head );
> }
> }
>
My question is, how to *optimize Remove(int Key)* method.
Maybe anyone have some docs, about SINGLE circular linked list's.
Thanks, for any help.
--
You can contact me by :
Google Talk: [EMAIL PROTECTED]
Skype: halfas.online.now
IRC: HalFas` (irc2.omnitel.net)
Home page: http://www.revidev.com/halfas/
One's leisure project: http://rvision.gamedev.lt/RVengine
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Algorithm Geeks" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/algogeeks
-~----------~----~----~----~------~----~------~--~---