请教一个问题(插入排序)
#include<stdio.h>#include<stdlib.h>
#define ERROR 0
#define OVERFLOW -2
#define LIST_INIT_SIZE 100
#define LISTINCREMENT 10
typedef struct
{
int *elem;
int length;
int listsize;
}SqList;
SqList L;
void ListInsert_Sq(int *L.elem,int i,int e)
{
int *p,*q,*newbase;
if(i<1||i>L.length-1)
return ERROR;
if(L.length>=L.listsize)
{
newbase=(int *)realloc(L.listsiza+LISTINCREMENT)*sizeof(int));
if(!newbase)
exit(OVERFLOW);
L.elem=newbase;
L.listsize+=LISTINCREMENT;
}
q=&(L.elem[i-1]);
for(p=&(L.elem[L.length-1]);p>=q;--p)
*(p+1)=*p;
*q=e;
++L.length;
}
main()
{
int i,l,e;
L.elem=(int*)malloc(LIST_INIT_SIZE*sizeof(int));
if(!L.elem)
exit(OVERFLOW);
L.length=10;
L.listsize=LIST_INIT_SIZE;
printf("Enter elememt: \n");
for(i=0;i<L.length;i++)
{
scanf("%d",&L.elem[i]);
}
printf("Enter l: \n");
scanf("%d",&l);
printf("Enter e: \n");
scanf("%d",&e)
ListInsert_Sq(L.elem,l,e);
for(i=0;i<L.length;i++)
{
printf("%d",L.elem[i]);
}
}
[[it] 本帖最后由 liyanhong 于 2008-10-16 09:27 编辑 [/it]]