数据结构实验题1(未完成)
来源:互联网 发布:下载3dmax软件 编辑:程序博客网 时间:2024/06/05 20:24
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#define MaxSize 50
typedef struct
{
char data[MaxSize];
int length;
}SqList;
void CreatteList(SqList *L,char a[],int n);//建表//
void InitList(SqList *L);//初始化
bool ListInsert(SqList * L,int i,char e);//插入
void DispList(SqList *L);//输出
int ListLength(SqList *L);//长度
bool ListEmpty(SqList *L);//空表
bool GetElem(SqList *L,int i,char e);//求元素值
int LocateElem(SqList *L,char e);//查找元素
void DestoryList(SqList *L);//销毁
bool ListDelete(SqList *L,int i,char e);//删除
void main()
{
SqList *L;
char e;
InitList(L);
ListInsert(L,'a',1);
ListInsert(L,'b',2);
ListDelete(L,'c',3);
ListDelete(L,'d',4);
ListDelete(L,'e',5);
printf("输出顺序表:");
DispList(L);
printf("表的长度为:");
ListLength(L);
printf("判断表是否为空:");
ListEmpty(L);
printf("输出第三个元素:");
GetElem(L,3,e);
printf("输出表中a的位置:");
LocateElem(L,'a');
return 0;
}
void CreatteList(SqList *L,char a[],int n)
{
int i;
L=(SqList *)malloc(sizeof(SqList));
for(i=0;i<n;i++)
{
L->data[i]=a[i];
}
L->length=n;
}
void InitList(SqList *L)
{
L=(SqList *)malloc(sizeof(SqList));
L->length=0;
}
bool ListInsert(SqList *L,int i,char e)
{
int j;
if(i<1||i>L->length+1)
return false;
i--;
for(j=L->length;j>i;j--)
L->data[j]=L->data[j-1];
L->data[i]=e;
L->length++;
return true;
}
void DispList(SqList *L)
{
int i;
for(i=0;i<L->length;i++)
printf("%c",L->data[i]);
printf("\n");
}
int ListLength(SqList *L)
{
return(L->length);
}
bool ListEmpty(SqList *L)
{
return(L->length==0);
}
bool GetElem(SqList *L,int i,char e)
{
if(i<1||i>L->length)
return false;
e=L->data[i-1];
return true;
}
int LocateElem(SqList *L,char e)
{
int i=0;
while(i<L->length&&L->data[i]!=e)
i++;
if(i>=L->length)
return 0;
else
return 1;
}
void DestoryList(SqList *L)
{
free(L);
}
bool ListDelete(SqList *L,int i,char e)
{
int j;
if(i<1||i>L->length)
return false;
i--;
e=L->data[i];
for(j=i;j<L->length-1;j++)
L->data[j]=L->data[j+1];
L->length--;
return true;
}
- 数据结构实验题1(未完成)
- 数据结构实验一(第1题)
- 《数据结构》实验一 (1)
- 数据结构实验一(1)
- 未完成DirectFB的实验
- bug整理1(未完成)
- 数据结构第1章上机实验题
- 数据结构(实验一)第2题
- 数据结构实验一(第3题)
- 数据结构课程上机实验题(一)
- 数据结构课程上机实验题(二)
- 数据结构课程上机实验题(三)
- 数据结构实验题3.6
- 数据结构实验指导1
- 《数据结构》 实验1
- 数据结构实验1
- 《数据结构》的实验1
- 《数据结构》 实验1
- 工具类-身份证
- 几种常见算法,面试经常考
- Linux下5种动态库运行时搜索路径的方法
- 使用天地图进行定位,获取坐标位置及省市等信息
- CentOS下rpm包与yum安装与卸载方法
- 数据结构实验题1(未完成)
- 双目测距原理
- 联想a890e刷机教程(图文)详细的手动线刷教程附线刷包
- Eclipse右键New菜单项如何进行自定义设置
- myeclipse隔天运行程序报错: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException
- MySql之内、外、左、右连接
- MUI,webview选项卡
- 开发准备--Android Studio的配置
- 开发准备--Android Studio中的版本管理git