• Post Reply Bookmark Topic Watch Topic
  • New Topic

Stuck sorting arrays. Need hints.  RSS feed

 
Werner Holt
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello all! I am stuck on this exercise form my homework and can't figure out how to complete it. I post what I have here. Please, give me some hints!



Write a method called isSorted that accepts an array of real numbers as a parameter and returns true if the list is in
sorted (nondecreasing) order and false otherwise. For example, if arrays named list1 and list2 store {16.1, 12.3,
22.2, 14.4} and {1.5, 4.3, 7.0, 19.5, 25.1, 46.2} respectively, the calls isSorted(list1) and isSorted(list2)
should return false and true respectively. Assume the array has at least one element. A one-element array is considered
to be sorted.


 
J. Kevin Robbins
Bartender
Posts: 1801
28
Chrome Eclipse IDE Firefox Browser jQuery Linux MySQL Database Netbeans IDE
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are very close. Think about how you would do it on paper. You would compare one number to the next one. If the condition remains true, compare the next two numbers. If the condition changes to false, stop comparing. Is that what you are doing?

 
Emil Jennings
Ranch Hand
Posts: 75
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Another hint if your results are different than the example: Look at the values you put in your arrays...
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!