标签:std art rmi i++ 选择排序 排序 exit form stdio.h
C实现
/* ============================================================================ Name : SeletionSort.c Author : eyan422 Version : Copyright : Your copyright notice Description : Hello World in C, Ansi-style ============================================================================ */ #include <stdio.h> #include <stdlib.h> int ScanForMin(int List[], int start ,int end) { int pos = start; int min = List[start]; for (int i = start; i <= end; i++) { if(List[i] < min) { min = List[i]; pos = i; } } return pos; } void Swap(int *left, int *right) { int tmp=0; tmp = *left; *left = *right; *right = tmp; } void SelectionSort(int List[], int N) { int MinPosition = 0; for (int i = 0; i < N; i++) { MinPosition = ScanForMin(List, i, N-1); printf("MinPosition = %d\n", MinPosition); Swap(&List[i],&List[MinPosition]); } } int main(void) { int tmp = 0; int List[]={5,4,3,6,7,2,1}; for(int i = 0; i < 7; i++) printf("%d\n", List[i]); SelectionSort(List, 7); for(int i = 0; i < 7; i++) printf("%d\n", List[i]); /* tmp = ScanForMin(List, 0, 6); printf("%d\n", tmp); printf("%d\n", List[tmp]); int a = 10; int b = 5; Swap(&a,&b); printf("\na=%d, b=%d\n",a,b); for(int i = 0; i < 7; i++) printf("%d\n", List[i]); */ return EXIT_SUCCESS; }
标签:std art rmi i++ 选择排序 排序 exit form stdio.h
原文地址:http://www.cnblogs.com/eyan422/p/6944076.html