Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Page 1 of 2 12 LastLast
Results 1 to 25 of 29

Thread: Sorting LinkedList

  1. #1
    Member
    Join Date
    Aug 2011
    Posts
    43
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Sorting LinkedList

    Im trying to do a bubble sort style process to my linkedList. It is a LinkedList of assignments, each with a set date stored as a string. I want to order the linkeList by the the date in which they were set. I can convert the strings to dates and compare them, my problem seems to be with changing the position of the assignments when i find out of they are in the incorrect order. Im using the index of the item in the linkedList to change the position as you will see below.

        public void orderSet()  
            {  
                SimpleDateFormat ValidFormat = new SimpleDateFormat("dd/MM/yyyy");  
                ListIterator<Assignment> iterator = assignmentList.listIterator(1);  
     
                boolean sorted = false;  
                while(!sorted)  
                {  
                    while(iterator.hasNext())  
                    {  
                        firstIndex = assignmentList.indexOf(iterator.previous());  
                        String previousDate = assignmentList.get(firstIndex).getDateSet();  
     
                        try  
                        {  
                            date = ValidFormat.parse(previousDate);  
                        }  
                        catch(ParseException pe)  
                        {  
                            System.out.println("ParseException" + pe);  
                        }  
     
                        index = assignmentList.indexOf(iterator.next());  
                        String checkSetDate = assignmentList.get(index).getDateSet();  
     
                        try  
                        {  
                            dateCheck = ValidFormat.parse(checkSetDate);  
                        }  
                        catch(ParseException pe)  
                        {  
                            System.out.println("ParseException" + pe);  
                        }  
     
                        if(dateCheck.before(date))  
                        {  
                            int temp = iterator.previousIndex();
                            int current = index;
                            int previous = current;
     
                            assignmentList.set(previous,assignmentList.get(index));
                            assignmentList.set(temp,assignmentList.get(firstIndex));  
     
                        }  
                    }  
                }  
            }
    Last edited by wdh; April 28th, 2012 at 07:31 AM.


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Sorting LinkedList

    Can you print out the list before the sort and again after the sort to show what the code is doing?
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Member
    Join Date
    Aug 2011
    Posts
    43
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Sorting LinkedList

    Quote Originally Posted by Norm View Post
    Can you print out the list before the sort and again after the sort to show what the code is doing?
    At the moment this code is doing nothing. I can explain what i am trying to do with it though
    While there is another element in the list, i store the index of the previous element, as well as get the date String which i parse into a date;
    I then get the index and date String from the current element the iterator is on and parse that date String into a date "dateCheck".
    I then check if dateCheck is before date, if so then i want to swap the index values of the current element and previous element around, so that they are then swapped in the list.
    Thats the idea anyway, and i am aware i only have one set assignment at the end, thats because i was unsure i had the correct method.

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Sorting LinkedList

    Let us know when you have working code to test.
    Or try debugging the code yourself. If you don't use an interactive debugger, add lots of println statements to show execution flow and the values of variables as they are changed.
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Member
    Join Date
    Aug 2011
    Posts
    43
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Sorting LinkedList

    When i run it in my tester, it goes through the rest of my methods but when it gets to this nothing happens. It still says the program is running so i put a println statement in the while loop and found out its just running through an infinite loop.

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Sorting LinkedList

    the while loop and found out its just running through an infinite loop
    Now you need to print out the values of the variables that are causing the infinite loop Then try to see why the code does not change them to allow the loop to exit.
    If you don't understand my answer, don't ignore it, ask a question.

  7. #7
    Member
    Join Date
    Aug 2011
    Posts
    43
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Sorting LinkedList

    Ive found the infinite loop is while(iterator.hasNext())
    Ive also put a println statement in before i check the dates and both dates are the same, both dates are always set to the first date in the list, i will have another look now and try to see why.

  8. #8
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Sorting LinkedList

    hasNext() will stay true until you remove all the items from the iterator.
    If you don't understand my answer, don't ignore it, ask a question.

  9. #9
    Member
    Join Date
    Aug 2011
    Posts
    43
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Sorting LinkedList

    I think its going someway to sorting the list, i changed firstIndex = assignmentList.indexOf(iterator.previous());
    to firstIndex = iterator.previousIndex(); and i now get some output using the new println statements:

    Testing inner while loop
    previous date = 27/02/2012current date = 23/02/2012
    int temp = 1 int current = 1
    Testing inner while loop
    previous date = 27/02/2012current date = 29/02/2012
    Testing inner while loop
    previous date = 29/02/2012current date = 22/02/2012
    int temp = 3 int current = 3

    I only have 4 assignments in there and according to this on the first run through it has done as i asked, on the second run through it hasnt printed the int values as it hasnt needed to go into the if statment as the dates are in order.
    Now its reached the end of the list it should go back through and sort again until it no longer needs to sort the list, then it will print out the whole assignment listed, hopefully in the order i want it. It appears just to stop after the first run through the list though.

  10. #10
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Sorting LinkedList

    How can I test it?
    If you don't understand my answer, don't ignore it, ask a question.

  11. #11
    Member
    Join Date
    Aug 2011
    Posts
    43
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Sorting LinkedList

    I realised i hadnt assigned anything to the boolean sorted so it would never break and print the assignmentList. Changed that now and the printed assignmentList is very wrong. I just have two of theassignments printed twice. That is the 2nd and 4th assignment in the list. Norm do you mean you want me to put up all of the files i have here?

  12. #12
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Sorting LinkedList

    Can you make a small simple program that compiles and execute and shows the problem. Hardcode the data into the program so no extra files are required.
    If you don't understand my answer, don't ignore it, ask a question.

  13. #13
    Member
    Join Date
    Aug 2011
    Posts
    43
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Sorting LinkedList

    Sorry its a bit of a mess, i usually seperate them into seperate files. It compiles and runs in the same way as before though.

    import java.text.ParseException;
    import java.text.SimpleDateFormat;
    import java.util.Date;
    import java.util.LinkedList;
    import java.util.ListIterator;
     
    public  class SortingLL  {
        private String MTitle;
        private String MIdentifier;
        private String ATitle;
        private String DateSet;
        private String DueDate;
        private String AAuthor;
        private String Weighting;
        static LinkedList<SortingLL> assignmentList;
        static Date date;
        static Date dateCheck;
        static Date tempDate;
        static int index;
        static int firstIndex;
     
        public SortingLL(String MTitle, String MIdentifier, String ATitle, String DateSet, String DueDate, String AAuthor, String Weighting)
        {
            this.MTitle = MTitle;
            this.MIdentifier = MIdentifier;
            this.ATitle = ATitle;
            this.DateSet = DateSet;
            this.DueDate = DueDate;
            this.AAuthor = AAuthor;
            this.Weighting = Weighting;        
        }
     
        public String getDateSet()
        {
            return DateSet;
        }
     
        public void setDateSet(String DateSet)
        {
            this.DateSet = DateSet;
        }
     
        public String toString()     {
    //        return  MTitle + "\n" + MIdentifier + "\n" + ATitle + "\n" + DateSet + "\n" + DueDate + "\n" + AAuthor + "\n" + Weighting + "\n";
            return  MTitle + " " + MIdentifier + "  " + ATitle + "  " + DateSet + "  " + DueDate + "  " 
                      + AAuthor + "  " + Weighting + "\n";
        }
     
        public static class Registry
        {
     
            public Registry()
            {
                assignmentList = new LinkedList<SortingLL>();
            }
     
            public void addAssignment(SortingLL aAssignment)
            {
                assignmentList.add(aAssignment);
            }
     
            public void orderSet()
            {
                SimpleDateFormat ValidFormat = new SimpleDateFormat("dd/MM/yyyy");
                ListIterator<SortingLL> iterator = assignmentList.listIterator(1);
     
                boolean sorted = false;
                while(!sorted)
                {
                    while(iterator.hasNext())                 {
                        firstIndex = iterator.previousIndex();
                        String previousDate = assignmentList.get(firstIndex).getDateSet();
     
                        try                      {
                            date = ValidFormat.parse(previousDate);
                        }
                        catch(ParseException pe)                    {
                            System.out.println("ParseException" + pe);
                        }
     
                        index = assignmentList.indexOf(iterator.next());
                        String checkSetDate = assignmentList.get(index).getDateSet();
     
                        try                     {
                            dateCheck = ValidFormat.parse(checkSetDate);
                        }
                        catch(ParseException pe)                     {
                            System.out.println("ParseException" + pe);
                        }
     
     //                   System.out.println("Testing inner while loop");
                        System.out.println("previous date = " + previousDate + " current date = " + checkSetDate);
     
                        if(dateCheck.before(date))                     {
                            int previous = firstIndex;//Index of previous assignment
                            int current = index; // Index of current assignment
     
                            SortingLL temporary = assignmentList.get(firstIndex);
     
                           // System.out.println("tempIdx =" + temp + " int currentIdx= " + current);
                            System.out.println("setting previous=" + previous + " to " + assignmentList.get(index));
                            assignmentList.set(previous, assignmentList.get(index));
                            System.out.println("setting current=" + current + " to " + temporary);
                            assignmentList.set(current, temporary);
     
                        }
                    }
                    sorted = true;
                }
                System.out.println("After aL=" + assignmentList.toString());
            }
        }
     
        public static void main(String[] args)      {
            Registry newAssignment = new Registry();
            newAssignment.addAssignment(new SortingLL("Java 1","ASM 1001","Java assignment 1","28/02/2012","10/05/2012","Mr Joe Bloggs","20%"));
            newAssignment.addAssignment(new SortingLL("Java 2","ASM 1002","Java assignment 2","27/02/2012","19/05/2012","Mr Joe Bloggs","20%"));
            newAssignment.addAssignment(new SortingLL("Java 3","ASM 1003","Java assignment 3","23/02/2012","22/05/2012","Mr Joe Bloggs","20%"));
            newAssignment.addAssignment(new SortingLL("Java 4","ASM 1004","Java assignment 4","29/02/2012","22/05/2012","Mr Joe Bloggs","20%"));
     
            System.out.println("Before aL=" + SortingLL.assignmentList.toString());
     
            System.out.println("Testing sort");
            System.out.println("************\n");
     
            newAssignment.orderSet();
     
     
        }
     
    }
    Last edited by wdh; April 28th, 2012 at 01:22 PM.

  14. #14
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Sorting LinkedList

    I see two dates. Which date is it supposed to sort on?
    If you don't understand my answer, don't ignore it, ask a question.

  15. #15
    Member
    Join Date
    Aug 2011
    Posts
    43
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Sorting LinkedList

    Quote Originally Posted by Norm View Post
    I see two dates. Which date is it supposed to sort on?
    in orderSort()
    date - is the previous date in the list
    dateCheck - is the current date in the list
    so dateCheck should be the date the iterator is currently on and it checks to see if it is before the previous date 'date'. If it is then the current assignment will switch places with the previous assignment in the list.

  16. #16
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Sorting LinkedList

    I changed the debug print out to give more info:
     
    import java.text.ParseException;
    import java.text.SimpleDateFormat;
    import java.util.Date;
    import java.util.LinkedList;
    import java.util.ListIterator;
     
    public  class SortingLL  {
        private String MTitle;
        private String MIdentifier;
        private String ATitle;
        private String DateSet;
        private String DueDate;
        private String AAuthor;
        private String Weighting;
        static LinkedList<SortingLL> assignmentList;
        static Date date;
        static Date dateCheck;
        static Date tempDate;
        static int index;
        static int firstIndex;
     
        public SortingLL(String MTitle, String MIdentifier, String ATitle, String DateSet, String DueDate, String AAuthor, String Weighting)
        {
            this.MTitle = MTitle;
            this.MIdentifier = MIdentifier;
            this.ATitle = ATitle;
            this.DateSet = DateSet;
            this.DueDate = DueDate;
            this.AAuthor = AAuthor;
            this.Weighting = Weighting;        
        }
     
        public String getDateSet()
        {
            return DateSet;
        }
     
        public void setDateSet(String DateSet)
        {
            this.DateSet = DateSet;
        }
     
        public String toString()     {
    //        return  MTitle + "\n" + MIdentifier + "\n" + ATitle + "\n" + DateSet + "\n" + DueDate + "\n" + AAuthor + "\n" + Weighting + "\n";
            return  MTitle + " " + MIdentifier + "  " + ATitle + "  " + DateSet + "  " + DueDate + "  " 
                      + AAuthor + "  " + Weighting + "\n";
        }
     
        public static class Registry
        {
     
            public Registry()
            {
                assignmentList = new LinkedList<SortingLL>();
            }
     
            public void addAssignment(SortingLL aAssignment)
            {
                assignmentList.add(aAssignment);
            }
     
            public void orderSet()
            {
                SimpleDateFormat ValidFormat = new SimpleDateFormat("dd/MM/yyyy");
                ListIterator<SortingLL> iterator = assignmentList.listIterator(1);
     
                boolean sorted = false;
                while(!sorted)
                {
                    while(iterator.hasNext())                 {
                        firstIndex = iterator.previousIndex();
                        String previousDate = assignmentList.get(firstIndex).getDateSet();
     
                        try                      {
                            date = ValidFormat.parse(previousDate);
                        }
                        catch(ParseException pe)                    {
                            System.out.println("ParseException" + pe);
                        }
     
                        index = assignmentList.indexOf(iterator.next());
                        String checkSetDate = assignmentList.get(index).getDateSet();
     
                        try                     {
                            dateCheck = ValidFormat.parse(checkSetDate);
                        }
                        catch(ParseException pe)                     {
                            System.out.println("ParseException" + pe);
                        }
     
     //                   System.out.println("Testing inner while loop");
                        System.out.println("previous date = " + previousDate + " current date = " + checkSetDate);
     
                        if(dateCheck.before(date))                     {
                            int temp = firstIndex;//Index of previous assignment
                            int current = index; // Index of current assignment
                            int previous = current; //
     
                           // System.out.println("tempIdx =" + temp + " int currentIdx= " + current);
                            System.out.println("setting temp=" + temp + " to " + assignmentList.get(index));
                            assignmentList.set(temp, assignmentList.get(index));
                            System.out.println("setting current=" + current + " to " + assignmentList.get(firstIndex));
                            assignmentList.set(current, assignmentList.get(firstIndex));
     
                        }
                    }
                    sorted = true;
                }
                System.out.println("After aL=" + assignmentList.toString());
            }
        }
     
        public static void main(String[] args)      {
            Registry newAssignment = new Registry();
            newAssignment.addAssignment(new SortingLL("Java 1","ASM 1001","Java assignment 1","28/02/2012","10/05/2012","Mr Joe Bloggs","20%"));
            newAssignment.addAssignment(new SortingLL("Java 2","ASM 1002","Java assignment 2","27/02/2012","19/05/2012","Mr Joe Bloggs","20%"));
            newAssignment.addAssignment(new SortingLL("Java 3","ASM 1003","Java assignment 3","23/02/2012","22/05/2012","Mr Joe Bloggs","20%"));
            newAssignment.addAssignment(new SortingLL("Java 4","ASM 1004","Java assignment 4","29/02/2012","22/05/2012","Mr Joe Bloggs","20%"));
     
            System.out.println("Before aL=" + SortingLL.assignmentList.toString());
     
            System.out.println("Testing sort");
            System.out.println("************\n");
     
            newAssignment.orderSet();
     
     
        }
     
    }
    Hopefully studying what is printed out will show you what is happening.
    If you don't understand my answer, don't ignore it, ask a question.

  17. #17
    Member
    Join Date
    Aug 2011
    Posts
    43
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Sorting LinkedList

    Thank you, that makes it clearer. So im setting the previous index to the correct date, but them im setting the current index to the same as the previous.

  18. #18
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Sorting LinkedList

    The code loses the first element and has two copies of the 3rd.
    Time for some design work with a paper and pencil.
    If you don't understand my answer, don't ignore it, ask a question.

  19. #19
    Member
    Join Date
    Aug 2011
    Posts
    43
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Sorting LinkedList

    Quote Originally Posted by Norm View Post
    The code loses the first element and has two copies of the 3rd.
    Time for some design work with a paper and pencil.
    Ive added a temporary assignment to hold the previous element, and them im setting that element at the current index. Ive updated my code at the top of this page, the output shows that its working correctly but i need to think of how im going to keep the loop running through the whole list and stop when all elements are in order. I know itll be to do with my boolean so ill will have a think.

  20. #20
    Member
    Join Date
    Aug 2011
    Posts
    43
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Sorting LinkedList

    Im still not sure how to get this to loop through again. I set the boolean sorted to false if the if statement comparing the dates is true. I also have to set the boolean sorted to true at some point otherwise the loop will never break. I did try a do while loop as well but that also didnt seem to help.

  21. #21
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Sorting LinkedList

    You need to post the code that shows the logic and that can be executed for testing.
    If you don't understand my answer, don't ignore it, ask a question.

  22. #22
    Member
    Join Date
    Aug 2011
    Posts
    43
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Sorting LinkedList

    Currently its the same as below. If the current date is before previous then sorted = false. It still only runs through the list once though, im not sure how to get it to run through until all elemtns are sorted and then also declare sorted as true.

    import java.text.ParseException;
    import java.text.SimpleDateFormat;
    import java.util.Date;
    import java.util.LinkedList;
    import java.util.ListIterator;
     
    public  class SortingLL  {
        private String MTitle;
        private String MIdentifier;
        private String ATitle;
        private String DateSet;
        private String DueDate;
        private String AAuthor;
        private String Weighting;
        static LinkedList<SortingLL> assignmentList;
        static Date date;
        static Date dateCheck;
        static Date tempDate;
        static int index;
        static int firstIndex;
     
        public SortingLL(String MTitle, String MIdentifier, String ATitle, String DateSet, String DueDate, String AAuthor, String Weighting)
        {
            this.MTitle = MTitle;
            this.MIdentifier = MIdentifier;
            this.ATitle = ATitle;
            this.DateSet = DateSet;
            this.DueDate = DueDate;
            this.AAuthor = AAuthor;
            this.Weighting = Weighting;        
        }
     
        public String getDateSet()
        {
            return DateSet;
        }
     
        public void setDateSet(String DateSet)
        {
            this.DateSet = DateSet;
        }
     
        public String toString()     {
    //        return  MTitle + "\n" + MIdentifier + "\n" + ATitle + "\n" + DateSet + "\n" + DueDate + "\n" + AAuthor + "\n" + Weighting + "\n";
            return  MTitle + " " + MIdentifier + "  " + ATitle + "  " + DateSet + "  " + DueDate + "  " 
                      + AAuthor + "  " + Weighting + "\n";
        }
     
        public static class Registry
        {
     
            public Registry()
            {
                assignmentList = new LinkedList<SortingLL>();
            }
     
            public void addAssignment(SortingLL aAssignment)
            {
                assignmentList.add(aAssignment);
            }
     
            public void orderSet()
            {
                SimpleDateFormat ValidFormat = new SimpleDateFormat("dd/MM/yyyy");
                ListIterator<SortingLL> iterator = assignmentList.listIterator(1);
     
                boolean sorted = false;
                while(!sorted)
                {
                    sorted = true;
                    while(iterator.hasNext())                 {
                        firstIndex = iterator.previousIndex();
                        String previousDate = assignmentList.get(firstIndex).getDateSet();
     
                        try                      {
                            date = ValidFormat.parse(previousDate);
                        }
                        catch(ParseException pe)                    {
                            System.out.println("ParseException" + pe);
                        }
     
                        index = assignmentList.indexOf(iterator.next());
                        String checkSetDate = assignmentList.get(index).getDateSet();
     
                        try                     {
                            dateCheck = ValidFormat.parse(checkSetDate);
                        }
                        catch(ParseException pe)                     {
                            System.out.println("ParseException" + pe);
                        }
     
     //                   System.out.println("Testing inner while loop");
                        System.out.println("previous date = " + previousDate + " current date = " + checkSetDate);
     
                        if(dateCheck.before(date))                     {
                            int previous = firstIndex;//Index of previous assignment
                            int current = index; // Index of current assignment
     
                            SortingLL temporary = assignmentList.get(firstIndex);
     
                           // System.out.println("tempIdx =" + temp + " int currentIdx= " + current);
                            System.out.println("setting previous=" + previous + " to " + assignmentList.get(index));
                            assignmentList.set(previous, assignmentList.get(index));
                            System.out.println("setting current=" + current + " to " + temporary);
                            assignmentList.set(current, temporary);
                            sorted = false;
     
                        }
                    }
     
                }
                System.out.println("After aL=" + assignmentList.toString());
            }
        }
     
        public static void main(String[] args)      {
            Registry newAssignment = new Registry();
            newAssignment.addAssignment(new SortingLL("Java 1","ASM 1001","Java assignment 1","28/02/2012","10/05/2012","Mr Joe Bloggs","20%"));
            newAssignment.addAssignment(new SortingLL("Java 2","ASM 1002","Java assignment 2","27/02/2012","19/05/2012","Mr Joe Bloggs","20%"));
            newAssignment.addAssignment(new SortingLL("Java 3","ASM 1003","Java assignment 3","23/02/2012","22/05/2012","Mr Joe Bloggs","20%"));
            newAssignment.addAssignment(new SortingLL("Java 4","ASM 1004","Java assignment 4","29/02/2012","22/05/2012","Mr Joe Bloggs","20%"));
     
            System.out.println("Before aL=" + SortingLL.assignmentList.toString());
     
            System.out.println("Testing sort");
            System.out.println("************\n");
     
            newAssignment.orderSet();
     
     
        }
     
    }

  23. #23
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Sorting LinkedList

    One thing I see is that you are printlng out the values that are being tested: if(dateCheck.before(date))

    For solving these kinds of problems you must use paper and pencil and work through your logic. In the code add enough printlns to see what is happening and then compare it with what you have worked out on paper.
    Last edited by Norm; April 29th, 2012 at 10:48 AM.
    If you don't understand my answer, don't ignore it, ask a question.

  24. #24
    Member
    Join Date
    Aug 2011
    Posts
    43
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Sorting LinkedList

    Quote Originally Posted by Norm View Post
    One thing I see is that you are printlng out the values that are being tested: if(dateCheck.before(date))
    Sorry, dont understand what you are saying . . .

  25. #25
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Sorting LinkedList

    For solving these kinds of problems you must use paper and pencil and work through your logic. In the code add enough printlns to see what is happening and then compare it with what you have worked out on paper.v
    If you don't understand my answer, don't ignore it, ask a question.

Page 1 of 2 12 LastLast

Similar Threads

  1. addInOrder LinkedList
    By PeskyToaster in forum Collections and Generics
    Replies: 1
    Last Post: April 6th, 2012, 06:16 AM
  2. LinkedList of String
    By oxnume in forum Collections and Generics
    Replies: 3
    Last Post: April 6th, 2012, 12:12 AM
  3. Weird problem with my linkedlist
    By clydefrog in forum Collections and Generics
    Replies: 19
    Last Post: February 22nd, 2012, 06:47 PM
  4. LinkedList Iterator
    By cpguy in forum What's Wrong With My Code?
    Replies: 1
    Last Post: November 16th, 2011, 09:51 PM
  5. LinkedList Objects
    By thedolphin13 in forum What's Wrong With My Code?
    Replies: 11
    Last Post: October 13th, 2010, 03:14 PM