I figured that out, need just resign pointers. |_1_| ----- |_2_|  ---del---
|_3_| ------ next {1}

|--------next------------------|

On Nov 16, 2007 8:26 PM, Dave <[EMAIL PROTECTED]> wrote:

>
> If the list contains at least two nodes, simply copy the data from the
> next node into the current one and delete the next node. It is an O(1)
> operation.
>
> Dave
>
> On Nov 11, 3:34 am, "Lukas Šalkauskas" <[EMAIL PROTECTED]>
> wrote:
> > 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- Hide quoted
> text -
> >
> > - Show quoted text -- Hide quoted text -
> >
> > - Show quoted text -
> >
>


-- 
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 algogeeks@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/algogeeks
-~----------~----~----~----~------~----~------~--~---

Reply via email to