#include<stdio.h>
#include<stdlib.h>
#include<ctype.h>
#include<malloc.h>
#define overflow -2
#define list_init_size 100
typedef struct{
int *elem;
int length;
int listsize;
}Sqlist;
void Initlist(Sqlist *L)
{
L->elem=(int *)malloc(list_init_size*sizeof(int));
if(!L->elem) exit(overflow);
L->length=0;
L->listsize=list_init_size;
}
void Input(Sqlist *L)
{
int length,i,x;
printf("/nPlease input the Slist length:/n");
scanf("%d",&length);
L->length=length;
printf("Please input %d elemts:/n",length);
for(i=0;i<length;i++)
{
scanf("%d",&x);
L->elem[i]=x;
}
}
void Output(Sqlist L)
{
int i;
printf("/nThe list elemt: /n");
for(i=0;i<L.length;i++)
printf("%3d",L.elem[i]);
printf("/n");
}
void Insert(Sqlist *L,int e)
{
int i;
int *newbase;
if(L->length>=L->listsize)
{
newbase=(int)malloc((10+list_init_size)*sizeof(int));
if(!newbase) exit(overflow);
L->elem=newbase;
L->listsize=L->listsize+10;
}
for(i=L->length-1; (i>=0)&&(L->elem[i]>e); i--)
L->elem[i+1]=L->elem[i];
L->elem[i+1]=e;
L->length++;
}
void main()
{
Sqlist L;
int e;
Initlist(&L);
Input(&L);
Output(L);
printf("/nPlease input the insert elemt:/n");
scanf("%d",&e);
Insert(&L,e);
Output(L);
}