lab10.2 - int i, maxIndex = 0 for(i = 0 i < size...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
Sheet1 Page 1 #include <stdio.h> #include <stdlib.h> #define SIZE 1000 int findMaxIndex(int input[], int size) void selectionSort(int input[], int size) void printArray(int input[], int start, int end) int main(){ int array[SIZE] int i for(i = 0 i < SIZE i++) array[i] = rand() printf("first 10 before sort\n") printArray(array,0,10) printf("last 10 before sort\n") printArray(array, 990, 1000) selectionSort(array, SIZE) printf("first 10 after sort\n") printArray(array,0,10) printf("last 10 after sort\n") printArray(array, 990, 1000) return 0 } int findMaxIndex(int input[], int size){
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: int i, maxIndex = 0 for(i = 0 i &lt; size i++) if (input[i] &gt; input[maxIndex]) maxIndex = i return maxIndex } void selectionSort(int input, int size){ if (size == 1) return int maxIndex = findMaxIndex(input, size) int temp = input[size - 1] Sheet1 Page 2 input[size - 1] = input[maxIndex] input[maxIndex] = temp selectionSort(input, size - 1) return } void printArray(int input, int start, int end){ int i for(i = start i &lt; end i++){ printf(&quot;%d &quot;, input[i]) } printf(&quot;\n&quot;) return }...
View Full Document

Page1 / 2

lab10.2 - int i, maxIndex = 0 for(i = 0 i &amp;amp;lt; size...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online