C数据结构的链表插入

来源:百度知道 编辑:UC知道 时间:2024/05/17 02:11:27
#include<stdio.h>
typedef int ElemType;
typedef int Status;
#define LIST_INIT_SIZE 100
#define LISTINCRMENT 10

typedef struct{
ElemType *elem;
int length;
int listsize;
}SqList;

Status InitList_Sq(SqList & L)
{
L.elem=(ElemType*)malloc(LIST_INIT_SIZE *sizeof(ElemType));
if(!L.elem)
exit(OVERFRLOW);
L.length=0;
L.listsize=LIST_INIT_SIZE ;
return OK;
}//Initlist.Sq

Status ListInsert(SqList &L,int i,ElemType e);
int main()
{
SqList list;
int i;
// int n=10;

InitList_Sq(list);
for(i=1;i<=10;i++)
ListInsert(&list,i,i);

// ListInsert(&list,i,n);//insert

for(i=0;i<10;i++)
printf("3%d",list.elem[i]);
return 0;
}

Status ListInsert(SqList &L,int i,ElemType e)
{
//
if(i<1||i>L.length+1)
return ERROR;
if(L.leng

。。
#include<stdio.h>
typedef int ElemType;
typedef int Status;
#define LIST_INIT_SIZE 100
#define LISTINCRMENT 10

typedef struct{
ElemType *elem;
int length;
int listsize;
}SqList;

Status InitList_Sq(SqList & L)
{
L.elem=(ElemType*)malloc(LIST_INIT_SIZE *sizeof(ElemType));
if(!L.elem)
exit(OVERFRLOW);
L.length=0;
L.listsize=LIST_INIT_SIZE ;
return OK;
}//Initlist.Sq

Status ListInsert(SqList &L,int i,ElemType e);
int main()
{
SqList list;
int i;
// int n=10;

InitList_Sq(list);
for(i=1;i<=10;i++)
ListInsert(&list,i,i);

// ListInsert(&list,i,n);//insert

for(i=0;i<10;i++)
printf("3%d",list.elem[i]);
return 0;
}