• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Problem with insertion sort

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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

 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
I was born with webbed fish toes. This tiny ad is my only friend:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic