标签:
#include<cstdio> #include<cstring> #include<cstdlib> #define MAXSIZE 10 typedef struct{ int r[MAXSIZE+1]; int length; }SqList; void InsertSort(SqList *L){ int i,j; for(i=2;i<=L->length;i++){ //把i插入对当前i-1前的已经排好序 中 if(L->r[i]<=L->r[i-1]){ L->r[0] = L->r[i]; for(j=i-1;L->r[j]>L->r[0];j--){ //蠕动吧, L->r[j+1] = L->r[j]; } L->r[j+1] = L->r[0]; } } } void Assignment(SqList *L,int len,int *a){ int i; L->length = len; for(i=1;i<=len;i++){ L->r[i] = a[i-1]; } return ; } void Output(SqList L){ int i; for(i=1;i<=L.length;i++){ printf("%d ",L.r[i]); } printf("\n"); return; } int main(){ int a[10] = {9,1,5,8,3,7,4,6,2,10}; SqList L; Assignment(&L,10,a); InsertSort(&L); Output(L); return 0; }
标签:
原文地址:http://www.cnblogs.com/zhuozhuo/p/5449614.html