版權(quán)說(shuō)明:本文檔由用戶(hù)提供并上傳,收益歸屬內(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++語(yǔ)言上機(jī)環(huán)境。2、會(huì)定義線性表的次序儲(chǔ)存構(gòu)造和鏈?zhǔn)絻?chǔ)存構(gòu)造。3、熟習(xí)次序表和鏈表的一些基本操作和應(yīng)用。4、加深對(duì)線性表的理解,逐漸培育解決實(shí)質(zhì)問(wèn)題的編程能力。二、實(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)的種類(lèi){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)康模?、定義棧和行列的結(jié)點(diǎn)種類(lèi)。2、掌握棧和行列插入和刪除元素在操作上的特色。3、熟習(xí)棧和行列的基本操作。4、加深對(duì)棧和行列的理解,逐漸培育解決實(shí)質(zhì)問(wèn)題的編程能力。二、實(shí)驗(yàn)內(nèi)容1、貨倉(cāng)算法#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ì)問(wèn)題的編程能力。二、實(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<<"截取的長(zhǎng)度:";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<<"刪除的長(zhǎng)度:";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. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶(hù)所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶(hù)上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶(hù)上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶(hù)因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 2025-2030全球自對(duì)焦激光切割頭行業(yè)調(diào)研及趨勢(shì)分析報(bào)告
- 2025-2030全球企業(yè)ESG服務(wù)行業(yè)調(diào)研及趨勢(shì)分析報(bào)告
- 天然礦泉水建設(shè)項(xiàng)目可行性研究報(bào)告申請(qǐng)立項(xiàng)備案
- 花崗石墓料行業(yè)深度研究分析報(bào)告(2024-2030版)
- 前角燈行業(yè)市場(chǎng)發(fā)展及發(fā)展趨勢(shì)與投資戰(zhàn)略研究報(bào)告
- 泡沫邊PP盒行業(yè)市場(chǎng)發(fā)展及發(fā)展趨勢(shì)與投資戰(zhàn)略研究報(bào)告
- 露點(diǎn)溫度傳感器行業(yè)市場(chǎng)發(fā)展及發(fā)展趨勢(shì)與投資戰(zhàn)略研究報(bào)告
- 2025年襯衫紡織項(xiàng)目可行性研究報(bào)告
- 烤肉制品項(xiàng)目可行性研究報(bào)告
- 2025年度公共設(shè)施消毒服務(wù)與效果評(píng)估合同
- 原料驗(yàn)收標(biāo)準(zhǔn)知識(shí)培訓(xùn)課件
- Unit4MyfamilyStorytime(課件)人教新起點(diǎn)英語(yǔ)三年級(jí)下冊(cè)
- 物流運(yùn)作管理-需求預(yù)測(cè)
- 財(cái)務(wù)管理專(zhuān)業(yè)《生產(chǎn)實(shí)習(xí)》教學(xué)大綱
- 一年級(jí)口算天天練(可直接打印)
- 新急救常用儀器設(shè)備操作流程
- 新人教版高中數(shù)學(xué)選擇性必修第一冊(cè)全套精品課件
- 2023年四川省自貢市中考數(shù)學(xué)真題(原卷版)
- 三年級(jí)數(shù)學(xué)混合運(yùn)算100題
- 通信工程安全生產(chǎn)手冊(cè)
- GB/T 8014-1987鋁及鋁合金陽(yáng)極氧化陽(yáng)極氧化膜厚度的定義和有關(guān)測(cè)量厚度的規(guī)定
評(píng)論
0/150
提交評(píng)論