#include<stdio.h>
#include<stdlib.h>
#define LIST_INIT_SIZE 100
#define LISTINCREMENT 10
#define OVERFLOW -2
typedef int ElemType;typedef struct
{
ElemType *elem;
int length;
int listsize;
}SqList;
void InitList_Sq(SqList &L)
{
L.elem=(ElemType*)malloc(LIST_INIT_SIZE*sizeof(ElemType));
if(!L.elem) exit(OVERFLOW);
L.listsize=LIST_INIT_SIZE;
}
void ListInsert_Sq(SqList &L,int i,ElemType e)
{
int q,p,*p,*q=(L.elem[i-1]);
if(i<1||i>L.length+1) return ERROR;
if(L.length>=L.listsize)
{
L.elem=(ElemType*)realloc(L.elem,L.listsize+LISTINCREMENT)*sizeof(ELemType));
if(!L.elem)
exit(OVERFLOW);
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;
} void ListDelete_Sq(SqList &L,int i,ElemType &e)
{
int p,q,*p==(L.elem[i-1]),*q;
if((i<1)||(i>L.length)) return ERROR;
p=&(L.elem[i-1]);
e=*p;
q=L.elem+L.length-1;
for(++p;p<=q;++p)
*(p-1)=*p;
--L.length;
} void main()
{
int j,i,e,L.elem[j];
SqList L;
L.length=0;
InitList_Sq(L);
printf("请输入链表数据元素:");
for(j=0;j<=6;j++)
{
scanf("%d",&L.elem[j]);
L.length++;
}
printf("请输入插入的元素:");
scanf("%d",&e);
printf("请输入新元素的位置:");
scanf("%d",&i);
ListInsert_Sq(L,i,e);
printf("请输入要删除第几个元素:");
scanf("%d",&i);
ListDelete_Sq(L,i,e);
return 0;
}
#include<stdlib.h>
#define LIST_INIT_SIZE 100
#define LISTINCREMENT 10
#define OVERFLOW -2
typedef int ElemType;typedef struct
{
ElemType *elem;
int length;
int listsize;
}SqList;
void InitList_Sq(SqList &L)
{
L.elem=(ElemType*)malloc(LIST_INIT_SIZE*sizeof(ElemType));
if(!L.elem) exit(OVERFLOW);
L.listsize=LIST_INIT_SIZE;
}
void ListInsert_Sq(SqList &L,int i,ElemType e)
{
int q,p,*p,*q=(L.elem[i-1]);
if(i<1||i>L.length+1) return ERROR;
if(L.length>=L.listsize)
{
L.elem=(ElemType*)realloc(L.elem,L.listsize+LISTINCREMENT)*sizeof(ELemType));
if(!L.elem)
exit(OVERFLOW);
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;
} void ListDelete_Sq(SqList &L,int i,ElemType &e)
{
int p,q,*p==(L.elem[i-1]),*q;
if((i<1)||(i>L.length)) return ERROR;
p=&(L.elem[i-1]);
e=*p;
q=L.elem+L.length-1;
for(++p;p<=q;++p)
*(p-1)=*p;
--L.length;
} void main()
{
int j,i,e,L.elem[j];
SqList L;
L.length=0;
InitList_Sq(L);
printf("请输入链表数据元素:");
for(j=0;j<=6;j++)
{
scanf("%d",&L.elem[j]);
L.length++;
}
printf("请输入插入的元素:");
scanf("%d",&e);
printf("请输入新元素的位置:");
scanf("%d",&i);
ListInsert_Sq(L,i,e);
printf("请输入要删除第几个元素:");
scanf("%d",&i);
ListDelete_Sq(L,i,e);
return 0;
}