实验报告课程名称 数据结构
姓名
学号
专业班级指导教师
目录
第二章线性表的查找、插入、删除. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1
1 .1顺序表的查找. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1
1 .2顺序表的插入. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .3
1 .3顺序表的删除. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7
单链表的建立、插入、删除. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .10
2.1单链表的建立尾插法. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .10
2.2单链表的插入. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .13
2.3单链表的删除. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .17
第三章栈. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .24
3.1链栈. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .24
3.2顺序栈. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .28
3.3队列. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .30
3.4杨辉三角. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .35
第四章串. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . .23
4.1字符串的建立. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .23
4.2顺序串的插入. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .25
1 .线性表的查找、插入、删除
1 .1顺序表的查找
程序
#include<stdio.h>
#include<stdl ib.h>
#include<mal loc.h>
#define OK 1
#define ERROR 0
#define TRUE 1
#define FALSE 0
#define ElemType int
#define MAXSIZE 100/*此处的宏定义常量表示线性表可能达到的最大长度*/typedef struct
{
ElemType elem[MAXSIZE]; /*线性表占用的数组空间*/int last; /*记录线性表中最后一个元素在数组elem[]中的位置(下标值)空表为-1*/
}Seq{l ist;int Locate(Seql ist L,ElemType e)
/*在顺序表L中查找与e相等的元素若L。 elem[i]=e,贝U找到该元素并返回i+1 若找不到则返回-1*/
{ int i=0; /*i为扫描计数器初值为0 即从第一个元素开始比较*/whi le
((i<=L. last)&&(L.elem[i]!=e))
/*顺序扫描表直到找到值为e的元素或扫描到表尾仍没找到*/ i++;if(i<=L. last)retu rn(i+1); /*若找到值为e的元素 贝返回其序号*/elseretu rn(-1); /*若没找到 贝返回空序号*/
}void main()
{
Seql ist l ;intp,q,r;int i ;printf("请输入线性标的长度:");scanf("%d",&r);l . last=r-1;printf("请输入线性表的各元素值 \n");for (i=0; i<=l . last; i++)
}printf("请输入要查找的元素值:\n");sea nf("%d",&q);p=Locate(l ,q);if(p==-1)printf("在此线性表中没有该元素!\n");elseprintf("该素在线性表中的位置为:%d\n",p);
执行结果:
错误分析:在编写过程中在编写主函数的时候有落下未编写的导致运行过程中不识别。
1 .2顺序表的插入
程序:
#include<stdio.h>#include<stdl ib.h>//#include<mal loc.h>
#define OK 1
#define ERROR 0
#define TRUE 1
#define FALSE 0
#define ElemType int
#define MAXSIZE 100typedef struct
{
ElemType elem[MAXSIZE];int last;
}SeqList;
//#include"common.h"
//#include"seql ist.h"int InsList(SeqList *L, int i ,ElemType e){
intk;if((i<1) | | (i>L->last+2))
{printf("插入位置i值不合法"); return(ERROR);}if(L->last>=MAXSIZE-1)
{printf("表已满无法插入"); return(ERROR);}for(k=L->last;k>=i-1;k--)
L->elem[k+1]=L->elem[k];
L->elem[i-1]=e;
L->last++;retu rn(OK);
}void main()
SeqList *l ;
{
intp,q,r;int i ; l=(SeqList*)mal loc(sizeof(SeqList));printf("请输入线性表的长度:");scanf("%d",&r);l->last=r-1;printf("请输入线性表的各元素值:\n");for(i=0; i<=l->last; i++)
{scanf("%d",&l->elem[i]);
}printf("请输入要插入的位置:\n");scanf("%d",&p);printf("请输入要插入的元素值:\n");scanf("%d",&q);
InsList(l ,p,q);for(i=0; i<=l->last; i++)
{printf("%d", l->elem[i]);
}
执行结果
}
收到10gbiz发来的7月份优惠方案,中国香港、美国洛杉矶机房VPS主机4折优惠码,优惠后洛杉矶VPS月付2.36美元起,香港VPS月付2.75美元起。这是一家2020年成立的主机商,提供的产品包括独立服务器租用和VPS主机等,数据中心在美国洛杉矶、圣何塞和中国香港。商家VPS主机基于KVM架构,支持使用PayPal或者支付宝付款。洛杉矶VPS架构CPU内存硬盘带宽系统价格单核512MB10GB1...
sharktech怎么样?sharktech (鲨鱼机房)是一家成立于 2003 年的知名美国老牌主机商,又称鲨鱼机房或者SK 机房,一直主打高防系列产品,提供独立服务器租用业务和 VPS 主机,自营机房在美国洛杉矶、丹佛、芝加哥和荷兰阿姆斯特丹,所有产品均提供 DDoS 防护。此文只整理他们家10Gbps专用服务器,此外该系列所有服务器都受到高达 60Gbps(可升级到 100Gbps)的保护。...
IMIDC发布了6.18大促销活动,针对香港、台湾、日本和莫斯科独立服务器提供特别优惠价格最低月付30美元起。IMIDC名为彩虹数据(Rainbow Cloud),是一家香港本土运营商,全线产品自营,自有IP网络资源等,提供的产品包括VPS主机、独立服务器、站群独立服务器等,数据中心区域包括香港、日本、台湾、美国和南非等地机房,CN2网络直连到中国大陆。香港服务器 $39/...