New Text Document

download New Text Document

If you can't read please download the document

description

Sorting

Transcript of New Text Document

#include#define MAX 5void selection_sort(int x[],int limits);int get_max(int x[],int limits);void print_array(int x[],int limits);main(0{ int scores[MAX]={84,67,77,72,44}; printf("original array:\n"); print_array(scores,5); selection_sort(sort,5); printf("sorted array:\n"); print_array(scores,5);/*function for an array with limits elements*/void selection_sort(int x[],int limits){int size,max,temp; for(size=limits;size>1;size--){max=get_max(x,size);temp=x[max];x[max]=x[size-1];x[size-1]=temp;}}/*function to return the largest element in the array*/int get_max(int x[],int size){int i,maxpos=0;for(i=0;ix[maxpos]?i:maxpos;return maxpos;}/*function to print an integer array of size limits*/void print_array(int x[],int limits){int i;for(i=0;i