I am trying to figure out how to sort an Array in Ascending order.
The Array I want to sort is:
array[4] // values: 1,3,2,4
I have a example code but are not really sure. I do understand the code almost but I wonder where the stored array are.
Is the sorted array simply: array ?
Does this code make this array in ascending order ?
Code:void exchange_sort(apvector <int> &array) { int i, j; int temp; // holding variable int arrayLength = array.length( ); for (i=0; i< (arrayLength -1); i++) // to represent element to be compared { for(j = (i+1); j < arrayLength; j++) // to represent the rest of the elements { if (array[i] < array[j]) { temp= array[i]; // swap array[i] = array[j]; array[j] = temp; } } } return; }



LinkBack URL
About LinkBacks


