Please help me find what's wrong with my code. For academic honesty I am just sharing the output right now but can provide if needed and the algorithm for binary search and selection sort which are as follows : BINARY SEARCH


Not sure if I'm interpreting your pseudo-code correctly.

In selection sort, make sure to keep track of the index of the smallest element, you'll need it for swapping. Swap two array elements, not an array element and a variable or maybe even two variables.

[Edit] Also: Do not min = values[i]; within the loop, as this might reset min even if it had been less.

  • I have just put my code for selection sort in the question above and hopefully you can give suggestions . Please check the code and let me know what can I improve.Plse help! – sk.76 Jun 16 '17 at 12:16
  • Keep track of the index of the smallest element, and swap two array elements, not variable min and array element values[i]. – Blauelf Jun 16 '17 at 13:30
  • I am not able to figure out how to keep the track of index of smallest element else than initialize a variable min and use it to swap because k will never have a value outside the loop. Plse help I am stuck in for long! – sk.76 Jun 16 '17 at 15:49
  • For example, when you assign to min, also assign the corresponding index (i or k) to another variable minIndex. Then swap values[i] and values[minIndex]. – Blauelf Jun 16 '17 at 15:52
  • I did change that as in edited in the code above (plse check) but then I got error messages that I have also edited in the output section of the question . Any suggestion will be appreciated. – sk.76 Jun 16 '17 at 16:33

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .