#include <string>
typedef int ElementType;
typedef struct Squential {
ElementType *Data;
int Length;
} Squential;
void EnterElement(Squential &List) {
int Len;
int x;
printf("Please input the Element Length:");
scanf("%d", &Len);
fflush(stdin);
List.Length = Len;
List.Data = (ElementType *) malloc(sizeof(ElementType) * List.Length);
for (int i = 0; i < List.Length; ++i) {
scanf("%d", &x);
List.Data[i] = x;
}
}
void PrintList(Squential List) {
for (int i = 0; i < List.Length; ++i) {
printf("%4d", List.Data[i]);
}
printf("\n");
}
void SelectionSorting(Squential List){
int Min,Terminal;
for (int i = 0; i < List.Length-1; ++i) {
Min=i;
for (int j = i+1; j <List.Length ; ++j) {
if (List.Data[Min]>List.Data[j]){
Min=j;
}
}
if (Min!=i){
Terminal=List.Data[i];
List.Data[i]=List.Data[Min];
List.Data[Min]=Terminal;
}
}
}
C/C++选择排序
最新推荐文章于 2024-05-20 19:43:04 发布