Monday, July 27, 2009

Another C programming question using arrays?

once again i dont understand how to solve the problem.... at all


Modify the selection sort function to count the number of exchanges neded to order an array of 50 random numbers. disply teh array before an after the sort. at the end disply the total exchanges neded to srt the array.

Another C programming question using arrays?
for(int x=0; x%26lt;n; x++)


{


int index_of_min = x;





for(int y=x; y%26lt;n; y++)


{


if(array[index_of_min] %26lt; array[y])


index_of_min = y;





}//inner for loop





int temp = array[x];


array[x] = array[index_of_min];


array[index_of_min] = temp;


count++:


}//outter for loop
Reply:Have you already implemented the selection sort?





One part of the sort is responsible for exchanging one element with another. If you coded the algorithm properly, this should occur within a conditional block.





Within this block you simply need to add a counter that will increment once, everytime the exchange occurs. Print out this counter when the sort completes.


No comments:

Post a Comment