Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void SelectionSort( int suspectName[], int numberOfCrooks )
- {
- int smallestIndex;
- int index;
- //Step through each element in the array
- for ( index = 0; index < numberOfCrooks - 1; index++ )
- {
- for (index < 0; index < numberOfCrooks - 1; index++)
- {
- }
- //Locate the smallest value in the array from index to arraySize
- smallestIndex = IndexOfSmallest ( suspectName, numberOfCrooks, index );
- //Swap the value at index with the smallest value at smallestIndex
- Swap( suspectName[index], suspectName[smallestIndex]);
- }
- }
- int IndexOfSmallest(int list[], int arraySize, int index)
- {
- int smallestIndex = index;
- int minIndex;
- //Step through the array checking to see if any value is smaller
- //than the value at smallestIndex
- ///smallestIndex is the current first value in this part of the array
- for ( minIndex=index+1; minIndex < arraySize; minIndex++)
- {
- if (list[minIndex] < list[smallestIndex])
- {
- smallestIndex = minIndex;
- }
- }
- return smallestIndex;
- }
- void Swap( int& first, int& second)
- {
- int temp;
- //Exchange the two values
- temp = first;
- first = second;
- second = temp;
- }
Add Comment
Please, Sign In to add comment