数据结构上机程序大全.docx

  1. 1、本文档共91页,可阅读全部内容。
  2. 2、有哪些信誉好的足球投注网站(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
  3. 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  4. 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
数据结构上机程序大全

第三周上机题第一题:创建一个顺序线性表,并输出。#include stdafx.h#includeiostreamusing namespace std;#define LIST_INIT_SIZE 100 struct StaticList{int elem[LIST_INIT_SIZE];int length;int listsize;};void InitList_StaticList(StaticList L){ L.length=0; L.listsize=LIST_INIT_SIZE; }int Ins_SList(StaticList L, int x){if(L.length=L.listsize){ return -1;}else{ L.elem[L.length]=x; L.length++; return 1;}}void print(StaticList L){for(int i=0;i=L.length-1;i++){ coutL.elem[i] ; //输出}coutendl;}int main(int argc, char* argv[]){StaticList SL;InitList_StaticList(SL); coutenter numbers:endl;while(1){int x;cinx; //输入if(x==9999) break;else{ Ins_SList(SL,x);}} coutThe array elems:endl; print(SL); return 0;}第二题:在第一题的基础上,增加删除线性表元素的子函数,实现对线性表第i个元素的删除操作。#include stdafx.h#includeiostreamusing namespace std;#define LIST_INIT_SIZE 100 struct StaticList{int elem[LIST_INIT_SIZE];int length;int listsize;};void InitList_StaticList(StaticList L){ L.length=0; L.listsize=LIST_INIT_SIZE; }int Ins_SList(StaticList L, int x){if(L.length=L.listsize){ return -1;}else{ L.elem[L.length]=x; L.length++; return 1;}}void print(StaticList L){for(int i=0;i=L.length-1;i++){ coutL.elem[i] ; //输出}coutendl;}int Del_SList(StaticList L, int i){ //删除表中下标为i处的元素if(L.length==0){return -1; //顺序表为空(没有元素可删),返回-1,删除失败}else{for(int j=i+1;j=L.length-1;j++){ L.elem[j-1]=L.elem[j]; //下标[i+1,length-1]的元素逐个前移}L.length--;return 1;}}int main(int argc, char* argv[]){StaticList SL; int i;InitList_StaticList(SL);coutenter numbers:endl; //输出while(1){int x;cinx; //输入if(x==9999) break;else Ins_SList(SL,x); } coutThe array elems:endl;print(SL); coutThe deleted elem order i is:endl; cini; Del_SList(SL,i);coutThe new array elems:endl;print(SL);return 0;}第三题:在第一题的基础上,增加删除线性表元素的子函数,实现对线性表表头元素和表尾元素的的删除操作。#include stdafx

文档评论(0)

173****7830 + 关注
实名认证
内容提供者

该用户很懒,什么也没介绍

1亿VIP精品文档

相关文档