c语言的顺序线性表,c语言数据结构顺序线性表编程

编译很多错误,麻烦帮忙修改下。。

#include

#define MAXSIZE 100

typedef int Elemtype

typedef struct

{

Elemtype data[MAXSIZE];

int last;

}SeqList;

SeqList SeqListInit()//初始化顺序线性表

{

Seqlist L;

L.Last=0;

return L;

}

SeqList SeqListOnit(SeqList L)//对顺序线性表进行赋值

{

int i=0;

while(L.last

{

scanf("%d",data[i++]);

L.last++;

}

return L;

}

void SeqListlong(SeqList L)//输出顺序线性表的长度

{

printf("顺序线性表的长度为%d",L.last);

}

int SeqListLocate(SeqList L,Elemtype x)//查找顺序线性表中的某元素

{

int i=1;

while(i<=L.last&&L.data[i-1]!=x)

i++;

if(i<=L.last)return i;

else return 0;

}

int SeqListEmpty(SeqList L)//判断顺序线性表是否为空

{

return(L.last==0?1:0);

}

void SeqListclear(SeqList L)//清空顺序线性表

{

L.last=0;

}

SeqList SeqListsee(SeqList L)//遍历顺序线性表

{

int i=0;

printf("查看顺序线性表的结果为:\n"

for(i=0;i<=L.last;i++)

{

printf("%d  ",L.data[i]);

}

}

SeqList SeqListInsert(SeqList L,int i,Elemtype x)//在顺序线性表插入某个数值

{

int j;

if(L.last==MAXSIZE)

printf("对不起,表已经满了,无法再插入");

if(i<1||i>L.last+1)

{

printf("插入位置错误");

exit(0);

}

for(j=L.last-1;j>=i-1;j--)

L.data[j+1]=L.data[j];

L.data[i-1]=x;

L.last++;

return L;

}

SeqList SeqListDetele(SeqList L,int i)//删除顺序线性表第i个数值

{

int j;

if(i<1||i>L.last)

{

printf("删除位置错误,退出");

exit(0);

}

for(j=i;j<=L.last-1;j++)

L.data[j-1]=L.data[j];

L.last--;

return L;

}

void main()

{

int c,b;

SeqList L;

L=SeqListInit();//初始化顺序线性表

printf("请对顺序线性表进行赋值,以#结束\n");

SeqListOnit(L);//对顺序线性表进行赋值

c=SeqListEmpty(L);//判断顺序线性表是否为空

if(c)

printf("表为空");

else printf("表不为空");

SeqListlong(L);//输出顺序线性表的长度

SeqListsee(L);//遍历顺序线性表

printf("请输入你要查找的元素\n");

scanf("%d",&c);

SeqListLocate(L,c);//查找顺序线性表中的某元素

printf("请输入你要插入的位置")

scanf("%d",&b);

printf("请输入你要插入的元素")

scanf("%d",&c);

SeqListInsert(L,b,c);

printf("请输入你要删除的元素");

scanf("%d",&c);

SeqListDetele(L,c);//删除顺序表中的某元素

SeqListclear(L);//清空顺序表

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值