




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
實(shí)驗(yàn)報(bào)告(數(shù)據(jù)構(gòu)造)學(xué)院:信息科學(xué)與技術(shù)學(xué)院班級(jí):姓名:日期:實(shí)驗(yàn)一線性表的基本操作一、實(shí)驗(yàn)?zāi)康?、熟習(xí)C或VC++語言上機(jī)環(huán)境。2、會(huì)定義線性表的次序儲(chǔ)存構(gòu)造和鏈?zhǔn)絻?chǔ)存構(gòu)造。3、熟習(xí)次序表和鏈表的一些基本操作和應(yīng)用。4、加深對(duì)線性表的理解,逐漸培育解決實(shí)質(zhì)問題的編程能力。二、實(shí)驗(yàn)內(nèi)容1、代碼:#include<>voidmain( ){intLA[100],LB[100],LC[100];intn,k=0,t=0;cout<<"請(qǐng)輸入線性表A中元素的個(gè)數(shù)(偶數(shù)):"<<endl;cin>>n;cout<<"輸入A中的元素:";for(inti=0;i<n;i++){cin>>LA[i];if(i%2==0)LB[k++]=LA[i];elseLC[t++]=LA[i];}cout<<"表B中的元素為:";for(i=0;i<n/2;i++)cout<<LB[i]<<"";cout<<endl;cout<<"表C中的元素為:";for(i=0;i<n/2;i++)cout<<LC[i]<<"";cout<<endl;}運(yùn)轉(zhuǎn)結(jié)果:2、代碼#include<>voidmain( ){intLA[100],LB[100];intn,i;cout<<"請(qǐng)輸入線性表A中的元素個(gè)數(shù):";cin>>n;cout<<"輸入A中的元素:";for(i=0;i<n;i++){cin>>LA[i];LB[i]=LA[i];}cout<<"表B中的元素為:"<<endl;for(i=0;i<n;i++)cout<<LB[i]<<"";cout<<endl;}運(yùn)轉(zhuǎn)結(jié)果:3、代碼#include<>voidmain( ){intLA[100];intn,i,k=48,t=50,num;cout<<"輸入LA中元素的個(gè)數(shù):";cin>>n;cout<<"輸入A中的元素:";cin>>LA[49];for(i=1;i<n;i++){cin>>num;if(num<=LA[49])LA[k--]=num;elseLA[t++]=num;}cout<<"新鏈表:";for(i=k+1;i<t;i++)cout<<LA[i]<<"";cout<<endl;}運(yùn)轉(zhuǎn)結(jié)果:4、代碼#include<>#include<>structnode{intnum;structnode*next;};structnode*creat( ){structnode*head,*p1,*p2;head=NULL;p1=p2=(structnode*)malloc(sizeof(structnode));cin>>p1->num;intn=0;while(p1->num!=0){n++;if(n==1)head=p1;elsep2->next=p1;p2=p1;p1=(structnode*)malloc(sizeof(structnode));cin>>p1->num;}p2->next=NULL;returnhead;}voidprint(structnode*head){structnode*p;p=head;do{cout<<(p->num)<<"";p=p->next;}while(p!=NULL);cout<<endl;}structnode*merge(structnode*LA,structnode*LB){structnode*p;p=LA;while(p->next!=NULL){p=p->next;}p->next=LB;returnLA;}voidmain( ){structnode*LA,*LB,*LC;LC=NULL;cout<<"請(qǐng)輸入單鏈表A:";LA=creat( );cout<<"請(qǐng)輸入單鏈表B:";LB=creat( );cout<<"新鏈表C:";LC=merge(LA,LB);print(LC);}運(yùn)轉(zhuǎn)結(jié)果:5、代碼#include<>#include<>structCirNode//定義每個(gè)結(jié)點(diǎn)的種類{intdata;//每一個(gè)人所擁有的密碼intnum;//每一個(gè)人在圈中的位序structCirNode*next;};inta[30];//人數(shù)要求≤30structCirNode*CreateList(intn)//生成n個(gè)結(jié)點(diǎn)的單向循環(huán)鏈表{structCirNode*L,*p,*q;inti;intj=1;L=q=(structCirNode*)malloc(sizeof(structCirNode));//成立一個(gè)不帶頭結(jié)點(diǎn)的單向循環(huán)鏈表if(!q)return0;printf("輸入每一個(gè)人的密碼:\n");q->num=j;scanf("%d",&q->data);j++;q->next=L;for(i=1;i<n;i++){p=(structCirNode*)malloc(sizeof(structCirNode));p->num=j;scanf("%d",&p->data);j++;q->next=p;p->next=L;q=q->next;}return(L);}structCirNode*DeleteList(structCirNode*L,intm,intn)//報(bào)m的人出列{inti,j=0,k=n;structCirNode*p,*q,*pre;pre=p=L;do{i=1;while(i<m-1){p=p->next;i++;}if(m==1){while(pre->next!=p)pre=pre->next;m=p->data;//獲得新的密碼a[j]=p->num;//獲得出列人的序號(hào)q=p;pre->next=p->next;p=p->next;free(q);L=pre=p;//讓新的報(bào)1的人作為頭結(jié)點(diǎn)k--;j++;}else{q=p->next;m=q->data;a[j]=q->num;p->next=q->next;p=q->next;free(q);L=pre=p;k--;j++;}}while(k>1);a[j]=p->num;//最后一個(gè)出列人的序號(hào)return(L);}intmain( ){structCirNode*L;inti,n,m;printf("請(qǐng)輸入人數(shù)n(小于30):");scanf("%d",&n);L=CreateList(n);printf("請(qǐng)輸入第一個(gè)m(大于0):");scanf("%d",&m);DeleteList(L,m,n);printf("出隊(duì)次序:\n");for(i=0;i<n;i++)printf("%d",a[i]);printf("\n");return0;}運(yùn)轉(zhuǎn)結(jié)果:實(shí)驗(yàn)二一、實(shí)驗(yàn)?zāi)康模薄⒍x棧和行列的結(jié)點(diǎn)種類。2、掌握棧和行列插入和刪除元素在操作上的特色。3、熟習(xí)棧和行列的基本操作。4、加深對(duì)棧和行列的理解,逐漸培育解決實(shí)質(zhì)問題的編程能力。二、實(shí)驗(yàn)內(nèi)容1、貨倉算法#include<iostream>usingnamespacestd;#include<>#defineMaxStackSize100#defineStackIncreMent10#include<string>#include<cstring>typedefstruct{int*base;int*top;intstacksize;}SqStack;intInitStack(SqStack&S)//初始棧{=(int*)malloc(MaxStackSize*sizeof(int));if(!return0;=;=MaxStackSize;return1;}intPush(SqStack&S,inte)//{
進(jìn)棧if{=(int*)realloc,+StackIncreMent)*sizeof(int));if(!exit(0);=+;+=StackIncreMent;}*++=e;return1;}intPop(SqStack&S,int&e)//{
出棧if==exit(0);e=*;return1;}intgetTop(SqStackS,SElemType&e)//得棧頂元素{if==return0;e=*;return1;}intempty(SqStackS)//判斷棧能否為空{(diào)if==return1;elsereturn0;}2、行列算法#include<iostream>usingnamespacestd;#include<>typedefstructQNode{intdata;structQNode*next;}QNode,*QueuePtr;typedefstruct{int*front;int*rear;}LinkQueue;intInitQueue(LinkQueue&Q)//初始行列{==(QueuePtr)malloc(sizeof(QNode));if(!return0;>next=NULL;return1;}intEnQueue(LinkQueue&Q,inte)//{QueuePtrp;p=(QueuePtr)malloc(sizeof(QNode));
入隊(duì)if(!p)return0;p->data=e;p->next=NULL;>next=p;=p;return1;}intDeQueue(LinkQueue&Q,int&e)//出隊(duì){QueuePrtp;if==return0;p=>next;e=p->data;>next=p->next;if==p)=;free(p);return1;}實(shí)驗(yàn)三一、實(shí)驗(yàn)?zāi)康模薄⒄莆沾幕静僮?。2、掌握串函?shù)的基本使用方法。3、加深對(duì)串的理解,逐漸培育解決實(shí)質(zhì)問題的編程能力。二、實(shí)驗(yàn)內(nèi)容#include<>#include<>#include<>chars[100];charT[100],T1[100];voidCreatString( ){cin>>s;}voidSubString(charT[],charS[],intpos,intlen){intk=0;for(inti=pos;i<pos+len;i++)T[k++]=S[i];T[k]='\0';}voidStrInsert(charS[],inti,charch){intt=strlen(S)-1;while(t>=i){S[t+1]=S[t];t--;}S[i]=ch;}voidStrDelele(charT[],charS[],inti,intlen){intk=0;for(intt=0;t<i;t++)T[k++]=S[t];intl=strlen(S);for(t=i+len;t<l;t++)T[k++]=S[t];}voidmain( ){while(1){cout<<"字符串辦理系統(tǒng)\n";cout<<"*********************\n";cout<<"*1、創(chuàng)立字符串*\n";cout<<"*2、提取指定串*\n";cout<<"*3、插入指定位*\n";cout<<"*4、刪除指定串*\n";cout<<"*5、退出系統(tǒng)*\n";cout<<"*********************\n";intchoise;cout<<"請(qǐng)選擇:";cin>>choise;switch(choise){case1:memset(s,'\0',100);cout<<"請(qǐng)輸入字符串:";CreatString( );break;case2://memset(T,'\0',100);//memset(s,'\0',100);intpos,len;cout<<"請(qǐng)輸入起點(diǎn):";cin>>pos;cout<<"截取的長度:";cin>>len;SubString(T,s,pos,len);printf("%s\n",T);break;case3://memset(s,'\0',100);intpos1;charch;cout<<"請(qǐng)輸入插入地點(diǎn):";cin>>pos1;cout<<"插入的字符:";cin>>ch;StrInsert(s,pos1,ch);printf("%s\n",s);break;case4://memset(s,'\0',100);//memset(T1,'\0',100);intpos2,len2;cout<<"請(qǐng)輸入刪除地點(diǎn):";cin>>pos2;cout<<"刪除的長度:";cin>>len2;StrDelele(T1,s,pos2,len2);printf("%s\n",T1);break;case5:return;}cout<<endl<<endl;}}運(yùn)轉(zhuǎn)結(jié)果:實(shí)驗(yàn)五一、實(shí)驗(yàn)?zāi)康模薄⒄莆张判虻幕居^點(diǎn)。2、熟習(xí)各樣內(nèi)部排序的方法。二、實(shí)驗(yàn)內(nèi)容代碼:#include<iostream>#include<algorithm>usingnamespacestd;intnum[100],n;intjudge(constvoid*a,constvoid*b){return*(int*)a-*(int*)b;}voidinput( ){cout<<"請(qǐng)輸入數(shù)據(jù)個(gè)數(shù):";cin>>n;for(inti=0;i<n;i++)cin>>num[i];}voidsortOfmaopao( ){sort(num,num+n);}voidsortOfxi
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 2025年度租賃合同到期后租客退租注意事項(xiàng)
- 2025年度股權(quán)轉(zhuǎn)讓回購的階段性付款協(xié)議
- 2025年度凈水器售后服務(wù)客戶投訴處理與滿意度提升協(xié)議
- 2025年度體育賽事賽事直播及網(wǎng)絡(luò)傳播轉(zhuǎn)委托合同
- 2025年度公司與員工業(yè)績(jī)?cè)鲩L對(duì)賭合同
- 吡咯-惡唑啉類化合物的化學(xué)發(fā)散性合成及其抑菌活性初步研究
- 酪氨酸介導(dǎo)脫硫石膏制備碳酸鈣工藝的研究
- 剪切波彈性成像評(píng)估小腿肌硬度對(duì)老年肌少癥的應(yīng)用價(jià)值
- 異戊酰胺對(duì)急性乙二醇中毒大鼠腦損傷的保護(hù)作用及機(jī)制研究
- 2025年集群通信系統(tǒng)(數(shù)字)項(xiàng)目合作計(jì)劃書
- 工科高等數(shù)學(xué)(下)知到章節(jié)答案智慧樹2023年上海海洋大學(xué)
- oppor11t刷全網(wǎng)通改全教程
- 兒童羽毛球教程
- 福建某機(jī)場(chǎng)二次雷達(dá)站基建工程施工組織設(shè)計(jì)
- 內(nèi)部控制-倉儲(chǔ)與存貨循環(huán)調(diào)查問卷
- 流程成熟度模型(PEMM)
- 高二英語期末考試試卷質(zhì)量分析報(bào)告
- 催化動(dòng)力學(xué)分析法及其應(yīng)用
- 外研版英語九年級(jí)下冊(cè)詞匯表音標(biāo)打印
- 聯(lián)合國教科文組織(UNESCO):可持續(xù)發(fā)展教育-路線圖
- 延長保修服務(wù)
評(píng)論
0/150
提交評(píng)論