• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem with insertion sort

 
Andrew Hodel
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Pie
Posts: 20742
30
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic