1 / 12
文档名称:

实验一线性表的基本操作实现及其应用.docx

格式:docx   大小:51KB   页数:12页
下载后只包含 1 个 DOCX 格式的文档,没有任何的图纸或源代码,查看文件列表

如果您已付费下载过本站文档,您可以点这里二次下载

分享

预览

实验一线性表的基本操作实现及其应用.docx

上传人:飞行的笑笑 2022/1/17 文件大小:51 KB

下载得到文件列表

实验一线性表的基本操作实现及其应用.docx

相关文档

文档介绍

文档介绍:实验 一 线性表的基本操作实现及其应用
一、实验目的
1、熟练掌握线性表的基本操作在两种存储结构上的实现。
2、会用线性链表解决简单的实际问题。
二、实验内容
题目一、该程序的功能是实现单链表的定义和操作。
p=p->next
true
p&&!(p->data==x)
false
返回 p
调用函数,传入参数 L,i, x
建立新结点 s,令
s->data=x;
p=L->next
程序清单:
#include<iostream>
using namespace std;
#include<>
#include<>
/* 预处理命令 */
#define OK 1;
#define ERROR 0;
#define OVERFLOW -1;
/* 单链表的结点类型 */
typedef struct LNode
{
int data;
struct LNode *next;
}LNode,*LinkedList;
/* 初始化单链表 */
LinkedList LinkedListInit()
{
空"<<endl;
cout<<"\t\t\t"<<"2. 求链表长度 "<<endl;
cout<<"\t\t\t"<<"3. 检查链表是否为空 "<<endl;
cout<<"\t\t\t"<<"4. 遍历链表 "<<endl;
cout<<"\t\t\t"<<"5. 从链表中查找元素 "<<endl;
cout<<"\t\t\t"<<"6. 从链表中查找与给定元素值相同的元素在表中的位
置"<<endl;
cout<<"\t\t\t"<<"7. 向链表中插入元素 "<<endl;
cout<<"\t\t\t"<<"8. 从链表中删除元素 "<<endl;
cout<<"\t\t\t"<<"9. 退出 "<<endl;
}
/* 主函数 */
int main()
{
链表长度
case 2:{
cout<<"\t\t\t 链表长度为: "<<LinkedListLength(L)<<endl; getch();
}
break;
查链表是否为空
case 3:{
if (!LinkedListEmpty(L))
{
cout<<"\t\t\t 链表不为空! "<<endl;
}
else
{
cout<<"\t\t\t 链表为空! "<<endl;
}
getch();
}
break;
历链表
case 4:{
LinkedListTraverse(L);
getch();
}
break;
链表中查找元素
case 5:{
cout<<"\t\t\t 请输入要查询的位置 i :";
int j;
cin>>j;
if (LinkedListGet(L,j))
{
cout<<"\t\t\t 位 置 i 的 元 素 值 为 :
"<<LinkedListGet(L,j)->data<<endl;
}
else
{
cout<<"\t\t\ti 大于链表长度! "<<endl;
}
getch();
}
break;
链表中查找与给定元素值相同的元素在表中的位置
case 6:{
cout<<"\t\t\t 请输入要查找的元素值: ";
int b;
cin>>b;
if (LinkedListGet1(L,b))
{
cout<<"\t\t\t 要 查 找 的 元 素 值 位 置 为 :
"<<LinkedListGet1(L,b)<<endl;
cout<<"\t\t\t 要查找的元素值内存地址为:
"<<LinkedListLocate(L,b)<<endl;

最近更新