This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Problem with insertion sort Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Problem with insertion sort" Watch "Problem with insertion sort" New topic
Author

Problem with insertion sort

Andrew Hodel
Greenhorn

Joined: Apr 04, 2013
Posts: 10
THHIS IS RESOLVED I FORGOT THE '=' IN MY WHILE STATEMENT
Howdy ya'll I writing an insertion sort and for some reason the first element of my sorted array isn't what it is supposed to be please help. this is the first few of my output
85925 56727 6849
85925 38 412 487 491 506 604 626
662 784 880 914 974 1271 1312 1451
1801 2231 2256 2346 2964 2974 3120 3169

Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

Andrew Hodel wrote:THHIS IS RESOLVED I FORGOT THE '=' IN MY WHILE STATEMENT


Yeah. That's why you shouldn't write



It's too easy to make a tiny error and write this instead:



Which as you now know, doesn't do what you expected. So you should almost never compare boolean values against the literals true and false; you should just write

Andrew Hodel
Greenhorn

Joined: Apr 04, 2013
Posts: 10
What are you talking about? My print was fine, I forgot to put <= so it wasn't comparing my first value in my sort method. But thanks for the little tid bit, that is a much cleaner way to write the if statement.
 
 
subject: Problem with insertion sort
 
Similar Threads
Sorting two dimensional array
Array problem
Parallel running quicksort
Comparing values
Error in my java code