1 Replies - 2796 Views - Last Post: 23 April 2012 - 08:22 PM Rate Topic: -----

#1 leany17  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 23-April 12

create a algorithm for selection sort, show as pseudocode or flowchart

Posted 23 April 2012 - 07:43 PM

hi, I am a mature age student learning java and need to use (23, 19, 35, 12, 30) as the values to create an algorithm for the selection sort, show it as pseudocode OR a flowchart, and desk check.
The bubble sort data we are need to change to selection sort is;
algorithm bubbleSort
Pre item is an array of values
n is the number of values in the array
Post itme has been sorted from losest to highest values
for k=0 to n -2
for j=0 to n -k -2
if item [j]>item[j+1]
temp =item[j]
item[j] =item[j=1]
item[j] =temp
end if
end for 
end for
end bubbleSort

I have tried reading different sources and am wondering if I am on the right track.. and how do I desk check?

Selectsort (int item[],int n) {
   int min,tmp,k,j,min_id;

   for (k=0; k<n-1; k++) {
       min = item[j];
       for (j=k+1; j<n; j++)
           if (item[j] < min) {
              min = item[j];
              min_id = j;
           }
       tmp = item[k];
       item[k] = item[min_id];
       item[min_id] = tmp;
   }
}



thanks

Mod edit - Please :code:

Is This A Good Question/Topic? 0
  • +

Replies To: create a algorithm for selection sort, show as pseudocode or flowchart

#2 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8327
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: create a algorithm for selection sort, show as pseudocode or flowchart

Posted 23 April 2012 - 08:22 PM

What you have is a bubble sort exactly as in that post

http://www.dreaminco...ost__p__1598082

and the following
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1