插入排序的順序表實(shí)現(xiàn)代碼
#include<stdio.h>
typedef struct {
int key;
}RecType;
typedef struct {
RecType R[100+1];
int Length;
}SqList;
#define N 11//為測試方便,直接輸入11個整數(shù)
void InsertSort(SqList *L)
{
int i,j;
for(i=2;i<=L->Length;i++)
if(L->R[i].key<L->R[i-1].key)
{
L->R[0]=L->R[i];
//value of under j compare with up decrease 1
for(j=i-1;L->R[0].key<L->R[j].key;j--)
L->R[j+1]=L->R[j];
L->R[j+1]=L->R[0];
}
}
int main()
{
SqList L;
int a[N],i,j,x;
for(i=1;i<N;i++)
scanf("%d",&L.R[i].key);
L.Length=i-1;
InsertSort(&L);
for(i=1;i<N;i++)
printf("%4d",L.R[i].key);
printf("\n");
return 0;
}
相關(guān)文章
C/C++: Inline function, calloc 對比 malloc
以下是對c/c++中的malloc函數(shù)與calloc函數(shù)的區(qū)別以及它們之間的聯(lián)系進(jìn)行了介紹,需要的朋友可以過來參考下2016-07-07在C語言中對utmp文件進(jìn)行查找和寫入操作的函數(shù)小結(jié)
這篇文章主要介紹了在C語言中對utmp文件進(jìn)行查找和寫入操作的函數(shù)小結(jié),包括pututline()函數(shù)和getutline()函數(shù)以及getutid()函數(shù),需要的朋友可以參考下2015-08-08