1 Replies - 829 Views - Last Post: 20 June 2012 - 12:44 PM

#1 Harro1  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 19-June 12

Understanding selection sort.

Posted 19 June 2012 - 08:04 PM

Hi I am having not sure if I am on the right track and could use some assistance before submitting my assisgnment.
I have an array of numbers that I need to create an algorithm for the selection sort, show it as pseudocode OR a flowchart, and desk check it before submitting. (23, 19, 35, 12, 30)is there something more I should fix or add?

For K= 0 to n – 1
   MAX = 0
   For j = 0 to n – k - 1
      If item[j] > item[MAX]
        MAX = item[j]
      end if
   end for
   swap item[n - k - 1] with item[MAX]
  end for
end SelectionSort
 


Is This A Good Question/Topic? 0
  • +

Replies To: Understanding selection sort.

#2 macosxnerd101  Icon User is offline

  • Self-Trained Economist
  • member icon




Reputation: 10183
  • View blog
  • Posts: 37,597
  • Joined: 27-December 08

Re: Understanding selection sort.

Posted 20 June 2012 - 12:44 PM

*Moved to Software Development*

You want to assign j to MAX, not item[j]. Remember that j is the index, and item[j] is the element. So if j is 10 and item[j] is 2, swapping item[MAX] is the same as swapping item[item[j]].
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1