jQuery in Action, 2nd edition*
The moose likes Java in General and the fly likes LinkedList Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "LinkedList" Watch "LinkedList" New topic
Author

LinkedList

Hunter McMillen
Ranch Hand

Joined: Mar 13, 2009
Posts: 492

Hey Everybody,

Im currently writing a program that is supposed to read in 10 integers from the user store them in linked list values and I'm supposed to keep them in ascending order at all times. I was wondering if there was a flaw in my logic somewhere that someone can spot because Im only getting correct results when the value im inserting is less than what I start my list at.

psuedocode


Any help would be great.
Thanks.
Hunter.


"If the facts don't fit the theory, get new facts" --Albert Einstein
Martijn Verburg
author
Bartender

Joined: Jun 24, 2003
Posts: 3274
    
    5

Here is a nice diagramtic explanation which I think will help you spot your problem...


Cheers, Martijn - Blog,
Twitter, PCGen, Ikasan, My The Well-Grounded Java Developer book!,
My start-up.
Hunter McMillen
Ranch Hand

Joined: Mar 13, 2009
Posts: 492

Thanks for replying, I read through the site and made some changes to my code but im still getting the same constraint error;



Whats happening is when I increment current if my if statement and the newLink value is > current value it moves current to current.next which is null.
This is where im lost.

Note(I realize this is Ada code but im trying to fix my logic)

Hunter.
Hunter McMillen
Ranch Hand

Joined: Mar 13, 2009
Posts: 492

Thanks for your help, I figured it out.

Hunter.
Martijn Verburg
author
Bartender

Joined: Jun 24, 2003
Posts: 3274
    
    5

No worries and kudos for working it out yourself! It's what we encourage here (hence why I sent you that link)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: LinkedList
 
Similar Threads
help me please??
Linked List Insertion and Deletion help
Linked List Sorting Problem
Linked List Sorting Problems
selection sort in a linked list