Insert sort of the order table implementation code

  • 2020-04-02 02:09:20
  • OfStack


#include<stdio.h>
typedef struct {
 int key;
}RecType;
typedef struct {
 RecType R[100+1];
 int Length;
}SqList;
#define N 11//For testing convenience, enter 11 integers directly
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;
}


Related articles: