下载此文档

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


文档分类:行业资料 | 页数:约12页 举报非法文档有奖
1/12
下载提示
  • 1.该资料是网友上传的,本站提供全文预览,预览什么样,下载就什么样。
  • 2.下载该文档所得收入归上传者、原创者。
  • 3.下载的文档,不会出现我们的网址水印。
1/12 下载此文档
文档列表 文档介绍
实验一线性表的基本操作实现及其应用.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;

实验一线性表的基本操作实现及其应用 来自淘豆网www.taodocs.com转载请标明出处.

相关文档 更多>>
非法内容举报中心
文档信息
  • 页数12
  • 收藏数0 收藏
  • 顶次数0
  • 上传人飞行的笑笑
  • 文件大小51 KB
  • 时间2022-01-17
最近更新