歡迎來到裝配圖網(wǎng)! | 幫助中心 裝配圖網(wǎng)zhuangpeitu.com!
裝配圖網(wǎng)
ImageVerifierCode 換一換
首頁 裝配圖網(wǎng) > 資源分類 > DOC文檔下載  

數(shù)據(jù)結(jié)構(gòu)上機(jī)試題教育試題

  • 資源ID:34973431       資源大?。?span id="ekkr0cs" class="font-tahoma">131.50KB        全文頁數(shù):22頁
  • 資源格式: DOC        下載積分:10積分
快捷下載 游客一鍵下載
會(huì)員登錄下載
微信登錄下載
三方登錄下載: 微信開放平臺(tái)登錄 支付寶登錄   QQ登錄   微博登錄  
二維碼
微信掃一掃登錄
下載資源需要10積分
郵箱/手機(jī):
溫馨提示:
用戶名和密碼都是您填寫的郵箱或者手機(jī)號(hào),方便查詢和重復(fù)下載(系統(tǒng)自動(dòng)生成)
支付方式: 支付寶    微信支付   
驗(yàn)證碼:   換一換

 
賬號(hào):
密碼:
驗(yàn)證碼:   換一換
  忘記密碼?
    
友情提示
2、PDF文件下載后,可能會(huì)被瀏覽器默認(rèn)打開,此種情況可以點(diǎn)擊瀏覽器菜單,保存網(wǎng)頁到桌面,就可以正常下載了。
3、本站不支持迅雷下載,請(qǐng)使用電腦自帶的IE瀏覽器,或者360瀏覽器、谷歌瀏覽器下載即可。
4、本站資源下載后的文檔和圖紙-無水印,預(yù)覽文檔經(jīng)過壓縮,下載后原文更清晰。
5、試題試卷類文檔,如果標(biāo)題沒有明確說明有答案則都視為沒有答案,請(qǐng)知曉。

數(shù)據(jù)結(jié)構(gòu)上機(jī)試題教育試題

數(shù)據(jù)結(jié)構(gòu)上機(jī)試題一、 順序表的操作(1)插入元素操作:將新元素x插入到順序表a中第i個(gè)位置。(2)刪除元素操作:刪除順序表a中第i個(gè)元素。#include<iostream.h>#include<stdlib.h>#define MAX 100;typedef structint data100;int length;sqlist;void init(sqlist &a)/線性表初始化 a.length=0;void insert(sqlist &a ,int i,int x)/ 插入元素操作int j;if(i<0|i>a.length+1|a.length=100);elsefor(j=a.length+1;j>i;j-)a.dataj=a.dataj-1;a.dataj=x;a.length+; void deleted(sqlist &a ,int i)/ 刪除元素操作int j;if(i<0&&i>a.length);elsefor(j=i;j<a.length;j+)a.dataj=a.dataj+1;a.length-;void main() sqlist a;/線性表為a int i,e,x,n,j,s;/i插入位置,e動(dòng)態(tài)建線性表要用,X插入元素,n表長 init(a);/構(gòu)造一個(gè)空表 cout<<"輸入表長 n: " cin>>n; cout<<"輸入表長為 "<<n<<" 個(gè)數(shù): " for(j=0;j<n;+j) cin>>e; insert(a,j,e); cout<<"插入前: " for(j=0;j<a.length ;j+) cout<<a.dataj<<" " cout<<"輸入要插入位置i: " cin>>i; cout<<"輸入要插入的元素x: " cin>>x; cout<<"打算在第"<<i<<"個(gè)位置插入元素"<<x ; insert(a,i-1,x);/由于從0開始,要構(gòu)造顯示從一開始,所以減1 cout<<"插入后結(jié)果: " for(j=0;j<a.length;j+) cout<<a.dataj<<" " cout<<"輸入要?jiǎng)h除的位置s: " cin>>s; deleted(a,s-1);/由于從0開始,要構(gòu)造顯示從一開始,所以減1 cout<<"刪除后結(jié)果: " for(j=0;j<a.length;j+) cout<<a.dataj<<" "二、單鏈表的操作(1)創(chuàng)建一個(gè)帶頭結(jié)點(diǎn)的單鏈表;(2)插入元素操作:將新元素x插入到單鏈表中第i個(gè)元素之后;(3)刪除元素操作:刪除單鏈表中值為x的元素;#include<iostream.h>#include<stdlib.h>typedef struct LNodeint data;struct LNode *next;LNode;/創(chuàng)建一個(gè)帶頭結(jié)點(diǎn)的長度長度長度為n的鏈表L;void createlist(LNode *&L ,int n)int i;LNode *p;L=(LNode *)malloc(sizeof(LNode);L->next=NULL;for(i=1;i<=n;i+)p=(LNode *)malloc(sizeof(LNode);cout<<"請(qǐng)輸入鏈表第"<<i<<"個(gè)元素"cin>>p->data;p->next=L->next;L->next=p;/插入元素操作:將新元素x插入到單鏈表L中第i個(gè)元素之后void insert(LNode *&L ,int i,int x)int j=0;LNode *p,*q;p=L;while(p->next!=NULL)j+;if(j=i)q=(LNode *)malloc(sizeof(LNode);/找到位置q->data=x;/放入數(shù)據(jù)q->next=p->next;p->next=q;break;p=p->next;if(p->next=NULL)q=(LNode *)malloc(sizeof(LNode);/找到位置q->data=x;/放入數(shù)據(jù)q->next=p->next;p->next=q;/刪除元素操作:刪除單鏈表中值為x的元素;void deleted(LNode *&L ,int x)LNode *p,*q;p=L;while(p->next!=NULL)if(p->next->data=x)q=p->next;p->next=p->next->next;free(q);p=p->next;void print(LNode *&L)LNode *p;p=L->next;while(p!=NULL)cout<<p->data<<" "p=p->next;void main()LNode * L,*p;/節(jié)點(diǎn)為Lint i,x,y,s,n;/i插入位置,X插入元素,y為刪除元素,n表長cout<<"輸入表長 n: "cin>>n;createlist(L,n);cout<<"輸出插入之前:"print(L);cout<<"請(qǐng)輸入插入的位置i: "cin>>i;cout<<"請(qǐng)輸入插入的元素x: "cin>>x;insert(L,i,x);cout<<"輸出插入后:"print(L);cout<<"請(qǐng)輸入刪除的元素y: "cin>>y;deleted(L,y);/刪除元素操作:刪除單鏈表中值為y的元素;cout<<"輸出刪除后:"print(L);三、在順序棧上實(shí)現(xiàn)將非負(fù)十進(jìn)制數(shù)轉(zhuǎn)換成二進(jìn)制數(shù)#include<iostream.h>#include<stdlib.h>#define MAX 100/在順序棧上實(shí)現(xiàn)將非負(fù)十進(jìn)制數(shù)x轉(zhuǎn)換成二進(jìn)制數(shù)void conversion(int &x)int stackMAX;int top=-1;int t;while(x)stack+top=x%2;x=x/2;while(top!=-1)t=stacktop-;cout<<t;void main()int x,t;cout<<"請(qǐng)輸入你要轉(zhuǎn)換的非負(fù)十進(jìn)制數(shù)x:"<<endl;cin>>x;cout<<"輸出轉(zhuǎn)換后的二進(jìn)制數(shù):"conversion(x);cout<<endl;四、在順序表中采用順序查找算法和折半查找算法尋找關(guān)鍵字X在順序表中的位置。#include<iostream.h>#include<stdlib.h>#define MAX 100/在順序表中采用順序查找算法和折半查找算法尋找關(guān)鍵字X在順序表中的位置typedef struct int dataMAX;int length;sqlist;void init(sqlist &a)/線性表初始化 a.length=0;void insert(sqlist &a ,int i,int x)/ 插入元素操作int j;if(i<0|i>a.length+1|a.length=100);elsefor(j=a.length+1;j>i;j-)a.dataj=a.dataj-1;a.dataj=x;a.length+; int search(sqlist &sq,int x)/順序查找算法int i;for(i=0;i<sq.length;i+)/順序表存儲(chǔ)從0開始if(sq.datai=x)return i;int hsearch(sqlist &sq,int low,int high,int x)/折半查找算法int mid;while(low<=high)mid=(low+high)/2;if(sq.datamid=x)return mid;else if(sq.datamid>x)high=mid-1;else if(sq.datamid<x)low=mid+1;void main() sqlist sq;/線性表為sq int i,e,x,y,n;/i插入位置,x,y要查找元素,n表長 init(sq);/構(gòu)造一個(gè)空表 cout<<"輸入表長 n: " cin>>n; cout<<"輸入表長為 "<<n<<" 個(gè)數(shù): " for(i=0;i<n;i+) cin>>e; insert(sq,i,e); cout<<"查找前(便于判斷):"<<endl; for(i=0;i<sq.length ;i+) cout<<sq.datai<<" " cout<<endl; cout<<"采用順序查找算法: "<<endl; cout<<endl; cout<<"輸入要查找元素關(guān)鍵字x " cin>>x; cout<<endl; cout<<"關(guān)鍵字"<<x<<"在順序表中的位置為"<<search(sq,x)+1<<endl; /下表從0開始,+1顯示時(shí),轉(zhuǎn)化成從1開始了 cout<<"采用折半查找算法: "<<endl; cout<<endl; cout<<"輸入要查找元素關(guān)鍵字y " cin>>y; cout<<endl; cout<<"關(guān)鍵字"<<y<<"在順序表中的位置為"<<hsearch(sq,1,sq.length,y)+1<<endl; 五、將無序數(shù)列使用直接插入排序算法和快速排序算法將其排成遞增有序數(shù)列。#include<iostream.h>#include<stdlib.h>#define MAX 100/將無序數(shù)列使用直接插入排序算法和快速排序算法將其排成遞增有序數(shù)列typedef struct int dataMAX;int length;sqlist;void init(sqlist &a)/線性表初始化 a.length=0;void insert(sqlist &a ,int i,int x)/ 插入元素,構(gòu)造無序數(shù)列int j;if(i<0|i>a.length+1|a.length=100);elsefor(j=a.length+1;j>i;j-)a.dataj=a.dataj-1;a.dataj=x;a.length+; /將哨兵放在a.datan中,被排序的記錄放在a.data0.n-1中,直接插入排序算法。void insertsort(sqlist &a)/直接插入排序算法int i,j;int n=a.length;for(i=n-2;i>=0;i-) if(a.datai>a.datai+1) a.datan=a.datai;/a.datan是哨兵 j=i+1; do a.dataj-1=a.dataj; j+;while(a.dataj<a.datan);a.dataj-1=a.datan;int Partition(sqlist &a,int i,int j)int pivot=a.datai;while(i<j)while(i<j&&a.dataj>=pivot) j-; if(i<j) a.datai+=a.dataj; while(i<j&&a.datai<=pivot) i+; if(i<j) a.dataj-=a.datai; a.datai=pivot; return i;void QuickSort(sqlist &a,int low,int high)/快速排序 int pivotpos; /劃分后的基準(zhǔn)記錄的位置if(low<high)/僅當(dāng)區(qū)間長度大于1時(shí)才須排序pivotpos=Partition(a,low,high); QuickSort(a,low,pivotpos-1); QuickSort(a,pivotpos+1,high); void main() sqlist sq1,sq2;/線性表為sq1,sq2 int i,e,x,n1,n2;/n表長 init(sq1);/構(gòu)造一個(gè)空表 cout<<"輸入表長 n1: " cin>>n1; cout<<"輸入表長為 "<<n1<<" 個(gè)數(shù): " for(i=0;i<n1;i+) cin>>e; insert(sq1,i,e);/ 插入元素,構(gòu)造無序數(shù)列 cout<<"無序數(shù)列為:"<<endl; for(i=0;i<sq1.length ;i+) cout<<sq1.datai<<" " cout<<endl; insertsort(sq1); cout<<"直接插入排序后數(shù)列為:"<<endl; for(i=0;i<sq1.length ;i+) cout<<sq1.datai<<" " cout<<endl; cout<<endl; cout<<endl; init(sq2);/構(gòu)造一個(gè)空表 cout<<"輸入表長 n2: " cin>>n2; cout<<"輸入表長為 "<<n2<<" 個(gè)數(shù): " for(i=0;i<n2;i+) cin>>e; insert(sq2,i,e);/ 插入元素,構(gòu)造無序數(shù)列 cout<<"無序數(shù)列為:"<<endl; for(i=0;i<sq2.length ;i+) cout<<sq2.datai<<" " cout<<endl; QuickSort(sq2,0, n2-1); cout<<"快速排序后數(shù)列為:"<<endl; for(i=0;i<sq2.length ;i+) cout<<sq2.datai<<" " cout<<endl;22借鑒試題

注意事項(xiàng)

本文(數(shù)據(jù)結(jié)構(gòu)上機(jī)試題教育試題)為本站會(huì)員(仙***)主動(dòng)上傳,裝配圖網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)上載內(nèi)容本身不做任何修改或編輯。 若此文所含內(nèi)容侵犯了您的版權(quán)或隱私,請(qǐng)立即通知裝配圖網(wǎng)(點(diǎn)擊聯(lián)系客服),我們立即給予刪除!

溫馨提示:如果因?yàn)榫W(wǎng)速或其他原因下載失敗請(qǐng)重新下載,重復(fù)下載不扣分。




關(guān)于我們 - 網(wǎng)站聲明 - 網(wǎng)站地圖 - 資源地圖 - 友情鏈接 - 網(wǎng)站客服 - 聯(lián)系我們

copyright@ 2023-2025  zhuangpeitu.com 裝配圖網(wǎng)版權(quán)所有   聯(lián)系電話:18123376007

備案號(hào):ICP2024067431號(hào)-1 川公網(wǎng)安備51140202000466號(hào)


本站為文檔C2C交易模式,即用戶上傳的文檔直接被用戶下載,本站只是中間服務(wù)平臺(tái),本站所有文檔下載所得的收益歸上傳人(含作者)所有。裝配圖網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)上載內(nèi)容本身不做任何修改或編輯。若文檔所含內(nèi)容侵犯了您的版權(quán)或隱私,請(qǐng)立即通知裝配圖網(wǎng),我們立即給予刪除!