- 0
- 0
- 约1.33万字
- 约 27页
- 2026-02-11 发布于江苏
- 举报
数据结构上机实验报告
学院:电子工程学院
专业:信息对抗技术
姓名:
学号:
教师:饶鲜
日期:
PAGE
3-
目录
TOC\o1-2\h\u实验一线性表 -2-
一、实验目的 -2-
二、实验代码 -2-
三、实验结果 -8-
四、个人思路 -9-
实验二栈和队列 -9-
一、实验目的 -9-
二、实验代码 -10-
三、实验结果 -15-
四、个人思路 -16-
实验三数组 -16-
一、实验目的 -16-
二、实验代码 -16-
三、实验结果 -18-
四、个人思路 -18-
实验四树 -18-
一、实验目的 -18-
二、实验代码 -19-
三、实验结果 -24-
四、个人思路 -25-
}
单链表结果截图见下方实验结果。
顺序表代码:
//顺序表逆置主文件.cpp
#includeiostream.h
#includestdio.h
#include顺序表结构类型定义.h
#include建立顺序表.h
#include输出顺序表.h
#include顺序表逆置.h
voidmain()
{
sequenlist*L;
creat(L);
print(L);
invert(L);//调用顺序表逆值的函数
print(L);
}
//顺序表的结构类型定义.h
typedefchardatatype;
constintmaxsize=1024;
typedefstruct
{datatypedata[maxsize];
intlast;
}sequenlist;
//建立顺序表.h
voidcreat(sequenlist*L)
{
L=newsequenlist;
L-last=0;
charch;
while((ch=getchar())!=*)
{
L-data[L-last]=ch;
L-last++;
}
}
//输出顺序表.h
voidprint(sequenlist*L)
{
for(inti=0;iL-last;i++)
coutL-data[i];
coutendl;
}
//顺序表逆置.h
voidinvert(sequenlist*L)
{charmid;
inti,j;
i=0;
j=L-last-1;
while(ij)
{
mid=L-data[i];
L-data[i]=L-data[j];
L-data[j]=mid;
i++;j--;
}
}
顺序表实验截图见下方实验结果。
已知由不具有头结点的单链表表示的线性表中,含有三类字符的数据元素(字母、数字和其他字符),试编写算法构造三个以循环链表表示的线性表,使每个表中只含有同一类的字符,且利用原表中的结点空间,头结点可另辟空间。(文件夹:习题2)
代码:
//分解单链表主程序文件.cpp
#includeiostream.h
#includestdio.h
#include单链表结构类型定义.h
#include建立单链表.h
#include输出单链表.h
#include输出循环链表.h
#include在循环链表中插入.h
#include分解单链表.h
voidmain()
{linklist*head,*letter,*digit,*other;
creat(head);
print1(head);
letter=newlinklist;
letter-next=letter;
digit=newlinklist;
digit-next=digit;
other=newlinklist;
other-next=other;
resolve(head,letter,digit,other);//调用分解单链表的函数
print2(letter);
print2(digit);
print2(other);
}
//单链表结构类型定义
typedefchardatatype;
typedefstructnode
{datatypedata;
structnode*next;
}linklis
原创力文档

文档评论(0)