ImageVerifierCode 换一换
格式:DOCX , 页数:27 ,大小:19.86KB ,
资源ID:4376702      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/4376702.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(数据结构上机考核试题及答案.docx)为本站会员(b****6)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

数据结构上机考核试题及答案.docx

1、数据结构上机考核试题及答案1、 顺序表的插入与删除 #define ListSize 10#define n 8#define Error printftypedef int DataType;typedef structDataType dataListSize;int length;seqlist;void deletelist(seqlist *L);void insertlist(seqlist *L);main()seqlist *L=0;int i;char c;printf(请按递减顺序输入%d个整数:n,n);for(i=0;idatai);L-length=n;printf(

2、n请选择:n);printf(A-插入-n);printf(B-删除-n);printf(C-退出-n);scanf(n%c,&c);while(c!=c&c!=C)if(c=A|c=a)insertlist(L);else deletelist(L);printf(当前顺序表中的数据是:n);for(i=0;ilength;i+)printf(%3d,L-datai);printf(n请再选择:n);printf(A-插入-n);printf(B-删除-n);printf(C-退出-n);scanf(n%c,&c);void insertlist(seqlist *L)int x,i,j;p

3、rintf(n请输入要插入的整数:);scanf(n%d,&x);printf(n在下面序列中插入%dn,x);for(i=0;ilength;i+)printf(%3d,L-datai);i=0;while(ilength&xdatai)i+;if(iL-length+1)Error(n插入位置错误!n);else if(L-length=ListSize)Error(n表溢出,无法插入!);else if(x=L-datai)printf(n重复插入,不允许!n);elseprintf(n将数据%d插入到第%d的位置上n,x,i);for(j=L-length-1;j=i;j-) /*=空

4、白处1=*/L-dataj+1=l-dataj;L-datai=x;L-length+; /*=*/void deletelist(seqlist *L)int x,i,j,num;printf(n请输入要删除的整数:);scanf(n%d,&x);printf(n在下面序列中删除%dn,x);for(i=0;ilength;i+)printf(%3d,L-datai);i=0;num=0;while(ilength&xdatai)i+;if(x!=L-datai)Error(n没找到要删除的整数!n);elsenum+;while(L-datai+1=x&ilength-1)i+;num+;

5、printf(n删除原表中从第%d个位置以后的%d个数据%dn,i-num+1,num,x);for(j=i+1;jlength-1;j+) /*=请在下面填入相应的语句=*/L-dataj-num=L-dataj;L-length=L-length-num; /*=*/_2 单链表的插入与删除 */#include #include #include #define Error printf#define n 5typedef struct nodeint data;struct node *next;ListNode;typedef ListNode * LinkList;LinkList

6、 Createlinklist(void);void Insertlinklist(LinkList head);void Deletelinklist(LinkList head);void Outputlinklist(LinkList head);main()LinkList head;char c;head=Createlinklist();printf(请选择:n);printf(A-插入-n);printf(B-删除-n);printf(C-退出-n);scanf(n%c,&c);while(c!=c&c!=C)if(c=A|c=a)Insertlinklist(head);els

7、e Deletelinklist(head);Outputlinklist(head);printf(n请再选择:n);printf(A-插入-n);printf(B-删除-n);printf(C-退出-n);scanf(n%c,&c);/*/LinkList Createlinklist()int x;LinkList head,s,r;head=(ListNode*)malloc(sizeof(ListNode);r=head;r-next=NULL;printf(请按递减顺序输入整数(输 0 结束):n);scanf(%d,&x);while (x!=0)s=(ListNode*)mal

8、loc(sizeof(ListNode);s-data=x;s-next=r-next;r-next=s;r=s;scanf(n%d,&x);return head;void Insertlinklist(LinkList head)int x;ListNode *p,*s;int i,j;printf(请输入要插入的整数:);scanf(%d,&x);p=head;j=0;while(p-next&xnext-data)j+;p=p-next;if(x=p-next-data)Error(重复插入,不允许!n);elses=(ListNode *)malloc(sizeof(ListNode

9、); /*=请在下面填入相应的语句=*/S-data=x;S-next=P-next;P-next=S; /*=*/ void Deletelinklist(LinkList head)int x;ListNode *p,*r;int i,j;printf(请输入要删除的整数:);scanf(%d,&x);p=head;r=head-next;while(r&xdata) p=r;r=r-next;if(r=NULL|x!=r-data)Error(没找到要删除的整数.n);else /*=空白处2=*/p-next=r-next;free(r); /*=*/void Outputlinkli

10、st(LinkList head)ListNode *p;p=head-next;printf(当前链表中数据为:n);while(p)printf(%6d,p-data);p=p-next;_/*=数据结构上机考核试题3=*/* 栈的操作 #define StackSize 10#define Error printftypedef int DataType;typedef structDataType dataStackSize;int top;SeqStack;void InitStack(SeqStack *s)s-top=0; int StackEmpty(SeqStack *S)i

11、f (S-top=0)return 1;else return 0;int StackFull(SeqStack *S)return S-top=StackSize;void Push(SeqStack *S,DataType x)if(StackFull(S)Error(栈溢出!); /*=空白处1=*/Else S-data+(S-top)=x; /*=*/DataType Pop(SeqStack *S) /*=空白处2=*/If(StackEmpty(S)Error(“Stack underflow”);Else return S-data-(S-top); /*=*/void con

12、version(int N,int B);main()int N,B;char ch;printf(进行数值转换请输入Y,退出请输入N:);scanf(n%c,&ch);while (ch=Y|ch=y)printf(请输入需要转换的十进制数:);scanf(%d,&N);printf(n请输入想要转换的进制数(2,8or16):);scanf(%d,&B);conversion(N,B);printf(继续转换请输入Y,退出请输入N:);scanf(n%c,&ch); void conversion(int N,int B) DataType i;SeqStack *S;InitStack(

13、S);while(N)Push(S,N%B); N=N/B; printf(转换的结果为:);while(!StackEmpty(S)i=Pop(S);switch(i)case 10:printf(%c,a);break;case 11:printf(%c,b);break;case 12:printf(%c,c);break;case 13:printf(%c,d);break;case 14:printf(%c,e);break;case 15:printf(%c,f);break;default:printf(%d,i); printf(n); _/*=数据结构上机考核试题4=*/*

14、队列的操作 */#include #define QueueSize 100#define Error printftypedef char DataType;typedef structint front;int rear;int count;DataType dataQueueSize;CirQueue;void InitQueue(CirQueue *Q) Q-front=Q-rear=0; Q-count=0; int QueueEmpty(CirQueue *Q) return Q-count=0; int QueueFull(CirQueue *Q) return Q-count=

15、QueueSize; void EnQueue(CirQueue *Q,DataType x) if(QueueFull(Q) Error(队列溢出!); e lse /*=空白处1=*/Q-count+;Q-dataQ-rear=x;Q-rear=(Q-rear+1)%QueueSize; /*=*/ DataType DeQueue(CirQueue *Q)DataType temp;if(QueueEmpty(Q)Error(队列下溢!);elsetemp=Q-dataQ-front; /*=空白处2=*/Q-count-;Q-front=(q-front+1)%QueueSize; /

16、*=*/return temp;void Inputch(CirQueue *Q);void Outputch(CirQueue *Q);main() CirQueue *Q=0; char ch; printf(n 继续进行请按Y,退出请按N:); scanf(n%c,&ch); while(ch=Y|ch=y) InitQueue(Q); Inputch(Q); Outputch(Q); printf(n 继续进行请按Y,退出请按N:); scanf(n%c,&ch); void Inputch(CirQueue *Q) char ch; printf(n 请输入字符串并以$为结束符:);

17、 scanf(%c,&ch); while(ch!=$) EnQueue(Q,ch); scanf(%c,&ch); void Outputch(CirQueue *Q) char ch; printf(你输入的字符串是:); while(!QueueEmpty(Q) ch=DeQueue(Q); printf(%c,ch); printf(n); /*=数据结构上机考核试题5=*/* 二叉树的遍历 */#include #include typedef char DataType;typedef struct nodeDataType data;struct node *lchild,*rc

18、hild;BinTNode;typedef BinTNode *BinTree;int count;void CreateBinTree(BinTree *T);void Levelorder(BinTree T);main()BinTree T;char ch1,ch2;printf(n请选择:n);ch1=y;while(ch1=y|ch1=Y)printf(nA-二叉树建立-);printf(nB-层次遍历-);printf(nC-退出-n);scanf(n%c,&ch2);switch(ch2)case a:case A:printf(请按先序输入建立二叉树存储的结点序列:n);Cre

19、ateBinTree(&T);break;case b:case B:printf(该二叉树的层次遍历序列为:n);Levelorder(T);break;case c:case C:ch1=n;break;default:ch1=n; void CreateBinTree(BinTree *T)char ch;scanf(n%c,&ch);if(ch=0) *T=NULL;else *T=(BinTNode*)malloc(sizeof(BinTNode);(*T)-data=ch;CreateBinTree(&(*T)-lchild);CreateBinTree(&(*T)-rchild)

20、; void Levelorder(BinTree T)int i,j;BinTNode *q20,*p;p=T;if(p!=NULL)i=1;qi=p;j=2;while(i!=j)p=qi;printf(%3c,p-data); /*=空白处1=*/ if(p-lchild!=NULL)qj=p-lchild; j+; if(p-rchild!=NULL)qj=p-rchild; j+; i+; /*=*/*=数据结构上机考核试题6=*/* 求二叉树叶子结点个数 */#include #include typedef char DataType;typedef struct nodeDat

21、aType data;struct node *lchild,*rchild;BinTNode;typedef BinTNode *BinTree;int count;void CreateBinTree(BinTree *T);void Leafnum(BinTree T);main()BinTree T;char ch1,ch2;printf(n请选择:n);ch1=y;while(ch1=y|ch1=Y)printf(nA-二叉树建立-);printf(nB-求叶子结点个数-);printf(nC-退出-n);scanf(n%c,&ch2);switch(ch2)case a:case

22、A:printf(请按先序输入二叉树存储的结点序列:n);CreateBinTree(&T);break;case b:case B:count=0;Leafnum(T);printf(该二叉树有%d个叶子.n,count);break;case c:case C:ch1=n;break;default:ch1=n;void CreateBinTree(BinTree *T) char ch; scanf(n%c,&ch); if(ch=0) *T=NULL; else *T=(BinTNode*)malloc(sizeof(BinTNode); (*T)-data=ch; CreateBin

23、Tree(&(*T)-lchild); CreateBinTree(&(*T)-rchild); void Leafnum(BinTree T) if(T) if(T-lchild=NULL&T-rchild=NULL) /*=空白处1=*/count+;Leafnum(T-lchild);Leafnum(T-rchild); /*=*/*=数据结构上机考核试题7=*/* 二分查找 */#include #define n 10main()int Rn,i,k,low,mid,high,m;char ch;printf(请按递增顺序输入10个整数:n,n);for(i=0;in;i+)scanf(%d,&Ri);printf(需要查找请输入 Y,否则输入 N:);scanf(n%c,&ch);while(ch=y|ch=Y)printf(请输入要查找的整数:n);scanf(n%d,&k);low=0;high=n-1;m=0;while(lowk) high=mid-1;else if(Rmidhigh)printf

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1