Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- // Init Some Global Vars
- int size = 10;
- int arr[10];
- int passCount = 0;
- // End
- // Function to print array
- void printArray(){
- int i = 0;
- for(i = 0; i<size; i++)
- {
- printf("%d \t",arr[i]);
- }
- }
- // Function To Selection Sort Array
- void selectionSort(){
- int i,j,maxIndex;
- for(i=0;i<size-1;i++){
- maxIndex = i;
- for(j = i+1; j < size; j++){
- if(arr[j] < arr[maxIndex]){
- maxIndex = j;
- }
- }
- if(maxIndex != i){
- int temp = arr[i];
- arr[i] = arr[maxIndex];
- arr[maxIndex] = temp;
- passCount++;
- }
- }
- }
- int main(){
- int i = 0;
- for(i = 0;i<size;i++)
- {
- printf("Enter Element For Position [ %d ] : ",i+1);
- scanf("%d",&arr[i]);
- }
- printf("Supplied Array Is : \n");
- printArray();
- printf("Array Created Starting Sort \n");
- selectionSort();
- printf("Sorted Array Is : \n");
- printArray();
- printf("Total Number of Passes : %d",passCount);
- }
Add Comment
Please, Sign In to add comment