Results 1 to 4 of 4
  1. #1
    bczm8703 is offline Member
    Join Date
    Mar 2011
    Posts
    5
    Rep Power
    0

    Default sorting linkedList??

    hi.. i have a LinkedList class and another Transaction class which are defined by myself.. my objective is to insert the transaction into the linkedList in chronological order... in my link list i have this method:

    Java Code:
     public void insertAcd (E newItem)
        {
            Node <E> pre,cur;
            E curItem;
    
            if (numItems==0)
            {
                head = new Node<E>(newItem);
                numItems++;
    
                return;
            }
    
            numItems++;
            curItem=head.item;
            if (curItem.compareTo(newItem)>=0)
            {
                head = new Node<E>(newItem, head);
    
                return;
            }
    
            pre = head;
            cur = pre.next;
            for(;cur!=null;)
            {
                curItem=cur.item;
    
                if (curItem.compareTo(newItem)>=0) break;
    
                pre = cur;
                cur = cur.next;
            }
           pre.next=new Node<E>(newItem,cur);
        }
    the transaction class is defined in this way:

    Java Code:
    Transaction trans = new Transaction (accountNumber,date,time,type,amount,place)

  2. #2
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

  3. #3
    bczm8703 is offline Member
    Join Date
    Mar 2011
    Posts
    5
    Rep Power
    0

    Default

    my question was how do i sort the linked list according to datetime...

    but i have solve it already... thx anyway

  4. #4
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

Similar Threads

  1. LinkedList and archives
    By veronica in forum New To Java
    Replies: 3
    Last Post: 02-04-2011, 04:54 PM
  2. LinkedList
    By [RaIdEn] in forum New To Java
    Replies: 7
    Last Post: 10-13-2009, 01:59 AM
  3. LinkedList help
    By jigglywiggly in forum New To Java
    Replies: 6
    Last Post: 09-19-2009, 08:24 AM
  4. LinkedList problem
    By Mika in forum New To Java
    Replies: 7
    Last Post: 02-18-2009, 03:10 PM
  5. how to use LinkedList
    By fred in forum Advanced Java
    Replies: 1
    Last Post: 07-24-2007, 02:52 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •