C语言数据结构顺序线性表

qiang5273 2012-05-03 10:53:21
编译有比较多错误,麻烦大虾帮我这个菜鸟修改一下,大一刚来学数据结构,这方面比较多不懂
。。#include<stdio.h>
#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<MAXSIZE&&L.data[i]!='#')
{
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);//清空顺序表
}
...全文
191 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
W170532934 2012-05-03
  • 打赏
  • 举报
回复

#include<stdio.h>
#include <stdlib.h>
#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<MAXSIZE&&L.data[i]!='#')
{
scanf("%d",L.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;
}

void 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);//清空顺序表
}

编译通过。至于逻辑上我没有去自习的看。

69,373

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧