数据结构上机实验报告学院:电子工程学院专业:信息对抗技术姓名:学号:教师:饶鲜日期:目录实验一线性表 -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""voidmain(){ linklist*head; creat(head); print(head); invert(head);//调用单链表逆置的函数 print(head);}//;typedefstructnode{ datatypedata; structnode*next;}linklist;//(linklist*&head)//采用尾插法建立具有结点的单链表{ charch; linklist*s,*r; head=newlinklist; r=head; while((ch=getchar())!='*') { s=newlinklist; s->data=ch; r->next=s; r=s; } r->next=NULL;}//(linklist*head){ linklist*p=head->next; while(p!=NULL) { cout<<p->data<<""; p=p->next; } cout<<endl;}//(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""voidmain(){ sequenlist*L; creat(L); print(L); invert(L);//调用顺序表逆值的函数 print(L);}//;constintmaxsize=1024;typedefstruct{datatypedata[maxsize];intlast;}sequenlist;//(sequenlist*&L){ L=newsequenlist; L->last=0; charch; while((ch=getchar())!='*') { L->data[L->last]=ch; L->last++; }}//(sequenlist*L){ for(inti=0;i<L->last;i++) cout<<L->data[i]<<""; cout<<endl;}//(sequenlist*L){charmid;inti,j;i=0;j=L->last-1;while(i<j){mid=L->data[i];L->data[i]=L->data[j];L->data[j]=mid;i++;j--;}}顺序表实验截图见下方实验结果。已知由不具有头结点的单链表表示的线性表中,含有三类字符的数据元素(字母、数字和其他字符),试编写
数据结构上机实验报告 来自淘豆网m.daumloan.com转载请标明出处.