- 9
- 0
- 约7.66千字
- 约 12页
- 2016-09-12 发布于湖北
- 举报
#define MaxSize 10
#includestdio.h
#include malloc.h
typedef char ElemType;
typedef struct
{
ElemType data[MaxSize];
int length;
}SqList;
void InitList(SqList * L)
{
L=(SqList * )malloc(sizeof(SqList));
L-length=0;
}
bool ListInsert(SqList * L,int i,ElemType e)
{
int j;
if(i1||iL-length+1)
return false;
i--;
for(j=L-length;ji;j--)
L-data[i]=L-data[j-1];
L-data[i]=e;
L-length++;
return true;
}
void DispList(SqList * L)
{
int i;
for(i=0;iL-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,ElemType e)
{
if(i1||iL-length)
return false;
e=L-data[i-1];
return true;
}
int LocateElem(SqList *L,ElemType e)
{
int i=0;
while(iL-lengthL-data[i]!=e)
i++;
if(iL-length)
return 0;
else
return i+1;
}
bool ListDelete(SqList *L,int i,ElemType e)
{
int j;
if(i1||iL-length)
return false;
i--;
e=L-data[i];
for(j=i;jL-length-1;j++)
L-length--;
return true;
}
void DestroyList(SqList *L)
{
free(L);
}
void main()
{
SqList *h;
int i=1;
ElemType e;
printf((1)初始化顺序表\n);
InitList(h);
printf((2)依次采用尾插法插入a b c d e\n);
ListInsert(h,1,a);
ListInsert(h,2,b);
ListInsert(h,3,c);
ListInsert(h,4,d);
ListInsert(h,5,e);
printf((3)输出循环单链表h:\n);
DispList(h);
printf((4)循环单链表h的长度为%d\n,ListLength(h));
printf((5)单链表h为%s\n,(ListEmpty(h)?空:非空));
GetElem(h,3,e);
printf((6)循环单链表h的第3个元素是%c\n,e);
GetElem(h,3,e);
printf((7)元素a的位置=%d\n,LocateElem(h,a));
printf((8)在第4个元素位置上插入元素f\n);
ListInsert(h,4,f);
printf((9)输出循环单链表表h:);
DispList(h);
printf((10)删除L的第3个元素\n);
ListDelete(h,3,e);
printf((11)输出循环单链表h:);
DispList(h);
printf((12)释放顺序表h\n);
DestroyList(h);
printf(雷志超 电信1301班\n);
}
//文件名:exp实验二7-4.cpp
#include stdio.h
#include malloc.h
#define MaxSize 100
#define MaxWidth 40
typedef char ElemType;
typedef struct node
{
ElemType data; //数据元素
struct node *lchild; //指向左孩子
您可能关注的文档
最近下载
- 中央电化教育馆函件.pdf VIP
- NB∕T 10891-2021 煤层气L型水平井钻完井设计规范.pdf
- 2025年金融风险管理师外汇期货合约特征与定价专题试卷及解析.pdf VIP
- 农业行业标准《ω-3多不饱和脂肪酸强化鸡蛋》 .pdf VIP
- 04CJ02 飞机库大门国标图集.pdf VIP
- 2025年一级建造师风险登记册在项目全生命周期中的应用专题试卷及解析.pdf VIP
- 综评 班主任操作手册2023版.pptx VIP
- 2025年无人机驾驶员执照应急响应计划审计专题试卷及解析.pdf VIP
- 2025年房地产经纪人市政配套设施(水、电、气、暖、通讯)勘察专题试卷及解析.pdf VIP
- 2025年信息系统安全专家零信任架构中的安全架构设计实战专题试卷及解析.pdf VIP
原创力文档

文档评论(0)