lab10.3 - 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> #include <string.h> #define SIZE 20 int findMaxIndex(char input[][10], int size) void selectionSort(char input[][10], int size) void printArray(char input[][10], int size) int main(){ char array[SIZE][10] = {"sleep","john","taxi","apple","rat","cat","eating", "long","mother","father","battle","home","control", "poke","dumb","zebra","yak","water","queen","idle"} int i printf("before sort\n") printArray(array, SIZE) printf("\n") selectionSort(array, SIZE) printf("after sort\n") printArray(array, SIZE) return 0 } int findMaxIndex(char input[][10], 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 (strcmp(input[i], input[maxIndex]) &gt; 0) maxIndex = i return maxIndex } void selectionSort(char input[10], int size){ if (size == 1) return int maxIndex = findMaxIndex(input, size) char temp[10] strcpy(temp, input[size - 1]) strcpy(input[size - 1], input[maxIndex]) Sheet1 Page 2 strcpy(input[maxIndex], temp) selectionSort(input, size - 1) return } void printArray(char input[10], int size){ int i for(i = 0 i &lt; size i++){ printf(&quot;%s\n&quot;, input[i]) } printf(&quot;\n&quot;) return }...
View Full Document

Page1 / 2

lab10.3 - 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