Re: Ordering Nodes within a Linked List......need help

From: nos (nos_at_nospam.com)
Date: 03/17/04


Date: Wed, 17 Mar 2004 01:56:54 GMT

homework eh?

"Newbie" <newbie@hotmail.com> wrote in message
news:c38861$5i0$1@news.netins.net...
> the linked list is to be built and sorted manually...
> not using the sun.java classes with the exception to:
> the exception classes and the comparable interface
>
> "Rhino" <rhino1@NOSPAM.sympatico.ca> wrote in message
> news:2bN5c.15077$E71.951718@news20.bellglobal.com...
> >
> > "Newbie" <newbie@hotmail.com> wrote in message
> > news:c3865k$uvk$1@news.netins.net...
> > > Subject says it all... I've to sort into order a list (using a linked
> > list).
> > >
> > > I'm trying to do this completely generically so that any object with a
> > > key(int) internal to the object, can be put onto the list and ordered
> > > appropriately.
> > >
> > > The problem I'm having is the compareT0 function.
> > >
> > > How can I compare the (key) of the incoming object to the (key) of an
> > object
> > > within a node?
> > >
> > > The is driving me insane... please assist me if you can and have the
> time.
> > >
> > > Thanks
> > >
> > > >>>>>>>>>>>>>>>>>CODE<<<<<<<<<<<<<<<<<<<<
> > > public class SList
> > > {
> > > protected Node header;
> > > protected Node previous;
> > > protected Node current;
> > >
> > > public SortList() //initialize nodes
> > > {
> > > header = null;
> > > previous = null;
> > > current = null;
> > > }
> > >
> > > public int compare(Object x)
> > > {
> > > int val;
> > >
> > > val = x.compareTo ( obj );
> > > }
> > >
> > > //node class
> > > protected class Node
> > > {
> > > protected Object obj;
> > > protected Node next;
> > >
> > > public Node(Object obj) {
> > > this.obj = obj;
> > > next = null;
> > > }
> > >
> > > }//end node class
> > > }//end SList class
> > >
> > >
> > Have you considered Collections? If not, read the chapter on Collections
> in
> > the Java Tutorial and you may find that it solves all your problems. Or
> not.
> >
> > Rhino
> >
> >
>
>



Relevant Pages

  • assistance required
    ... I'm obviously too dumb to follow the textbook ... >> Have you considered Collections? ... > the exception classes and the comparable interface ...
    (comp.lang.java.programmer)
  • Re: Ordering Nodes within a Linked List......need help
    ... the exception classes and the comparable interface ... > Have you considered Collections? ...
    (comp.lang.java.programmer)