下载此文档

数据结构上机实验报告.docx


文档分类:高等教育 | 页数:约41页 举报非法文档有奖
1/41
下载提示
  • 1.该资料是网友上传的,本站提供全文预览,预览什么样,下载就什么样。
  • 2.下载该文档所得收入归上传者、原创者。
  • 3.下载的文档,不会出现我们的网址水印。
1/41 下载此文档
文档列表 文档介绍
数据结构上机实验报告
学院:电子工程学院
专业:信息对抗技术
姓名:
学号:
教师:饶鲜
日期:
目录
实验一线性表 - 2 -
一、实验目的 - 2 -
二、实验代码 - 2 -
三、实验结果 - 8 -
四、个人思路 - 9 -
实验二栈和队列 - 9 -
一、实验目的 - 9 -
二、实验代码 - 10 -
三、实验结果 - 15 -
四、个人思路 - 16 -
实验三数组 - 16 -
一、实验目的 - 16 -
二、实验代码 - 16 -
三、实验结果 - 18 -
四、个人思路 - 18 -
实验四树 - 18 -
一、实验目的 - 18 -
二、实验代码 - 19 -
三、实验结果 - 24 -
四、个人思路 - 25 -
实验一线性表
一、实验目的
熟悉线性表的顺序和链式存储结构
掌握线性表的基本运算
能够利用线性表的基本运算完成线性表应用的运算
二、实验代码
设有一个线性表E={e1, e2, …, en-1, en},设计一个算法,将线性表逆置,即使元素排列次序颠倒过来,成为逆线性表E’={ en, en-1 , …, e2 , e1 },要求逆线性表占用原线性表空间,并且用顺序表和单链表两种方法表示,分别用两个程序来完成。(文件夹****题1)
代码:
单链表代码:
//
#include<>
#include<>
#include""
#include""
#include""
#include""
void main()
{
linklist*head;
creat(head);
print(head);
invert(head);//调用单链表逆置的函数
print(head);
}
//
typedef char datatype;
typedef struct node
{
datatype data;
struct node *next;
}linklist;
//
void creat(linklist*&head)
//采用尾插法建立具有结点的单链表
{
char ch;
linklist *s,*r;
head=new linklist;
r=head;
while((ch=getchar())!='*')
{
s=new linklist;
s->data=ch;
r->next=s;
r=s;
}
r->next=NULL;
}
//
void print(linklist *head)
{
linklist*p=head->next;
while(p!=NULL)
{
cout<<p->data<<" ";
p=p->next;
}
cout<<endl;
}
//
void invert(linklist*head)
{
linklist*p,*q,*r;
p=head->next;
q=p->next;
while(q!=NULL)
{
r=q->next;
q->next=p;
p=q;
q=r;
}
head->next->next=NULL;
head->next=p;
}
单链表结果截图见下方实验结果。
顺序表代码:
//
#include<>
#include<>
#include""
#include""
#include""
#include""
void main()
{
sequenlist*L;
creat(L);
print(L);
invert(L);//调用顺序表逆值的函数
print(L);
}
//
typedef char datatype;
const int maxsize=1024;
typedef struct
{ datatype data[maxsize];
int last;
}sequenlist;
//
void creat(sequenlist*&L)
{
L=new sequenlist;
L->last=0;
char c

数据结构上机实验报告 来自淘豆网www.taodocs.com转载请标明出处.

非法内容举报中心
文档信息
  • 页数41
  • 收藏数0 收藏
  • 顶次数0
  • 上传人陈潇睡不醒
  • 文件大小369 KB
  • 时间2018-04-17