網(wǎng)絡(luò)設(shè)計方案某報告_第1頁
網(wǎng)絡(luò)設(shè)計方案某報告_第2頁
網(wǎng)絡(luò)設(shè)計方案某報告_第3頁
網(wǎng)絡(luò)設(shè)計方案某報告_第4頁
網(wǎng)絡(luò)設(shè)計方案某報告_第5頁
已閱讀5頁,還剩5頁未讀, 繼續(xù)免費閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)

文檔簡介

實驗名稱:第9章實驗實驗類型:驗證性實驗姓名:車紅岫實驗日期:2013.6問題描述以下四個驗證性實驗都做。(1)順序查找驗證(2)折半查找驗證(3)二叉排序樹的建立(4)哈希表的建立數(shù)據(jù)結(jié)構(gòu)設(shè)計順序查找驗證typedefstruct{KeyType*elem;//零號單元留空intlength;//表長度}SSTable;折半查找驗證 intscore[100]; intlength; intkey;二叉排序樹的建立typedefstructnode{ datatypekey; structnode*lchild,*rchild;}bsnode;(4)哈希表的建立typedefstructLnode{intdata;structLnode*next;}Lnode,*ListLink;//建立鏈表結(jié)點typedefstruct{intpos;ListLinkfirstnode;//建立數(shù)組結(jié)點}HashBox;typedefstruct{HashBoxHArrary[INIT_MAXSIZE];//建立哈希數(shù)組(哈希表的地址表頭)}HashArray;3.算法設(shè)計4.界面設(shè)計(1)順序查找驗證折半查找驗證二叉排序樹的建立(4)哈希表的建立5.運行、測試(一)順序查找驗證(1)運行程序,顯示菜單輸入n(3)輸出結(jié)果折半查找驗證(1)運行程序,顯示菜單輸入n(3)輸出結(jié)果二叉排序樹的建立運行程序,顯示菜單(2)輸入n(3)輸出結(jié)果哈希表的建立運行程序,顯示菜單(2)輸入n(3)輸出結(jié)果實驗收獲及思考建立哈希表時沒有考慮沖突處理問題,做程序時要謹慎小心。附錄:源代碼(1)順序查找驗證#include<stdio.h>#include<stdlib.h>#defineMAX_LENGTH100typedefintKeyType;typedefstruct{KeyType*elem;//零號單元留空intlength;//表長度}SSTable;intSearch_Seq(SSTableST,KeyTypekey){inti;ST.elem[0]=key;//“哨兵”for(i=ST.length;ST.elem[i]!=key;i--);//從后往前找returni;//找不到時,i為0}voidmain(){inti,key;SSTableT;T.elem=(KeyType*)malloc(sizeof(KeyType));printf("輸入數(shù)據(jù)個數(shù)\n");scanf("%d",&T.length);for(i=1;i<=T.length;i++){printf("輸入數(shù)據(jù)%d;\n",i);scanf("%d",&T.elem[i]);}for(i=1;i<=T.length;i++)printf("%5d",T.elem[i]);printf("\n輸入要查找的數(shù)據(jù)\n");scanf("%d",&key);i=Search_Seq(T,key);printf("位置是%d\n",i);system("pause");}(2)折半查找驗證#include<stdio.h>#include<stdlib.h>#defineOK1#defineERROR0voidmain(){ intscore[100]; intlength; intkey; printf("輸入數(shù)據(jù)個數(shù):\n"); scanf("%d",&length); for(inti=1;i<=length;i++) {printf("輸入第%d個元素",i); scanf("%d",&score[i]); } printf("\n輸入要查找的關(guān)鍵字\n"); scanf("%d",&key); intlow,high,mid; low=1; high=length; while(low<=high) { mid=(low+high)/2; if(score[mid]==key)//找到待查元素 {printf("數(shù)據(jù)位置%d",mid); system("pause"); } elseif(key<score[mid]) high=mid-1;//繼續(xù)在前半?yún)^(qū)間進行查找 elseif(key>score[mid]) low=mid+1;//繼續(xù)在后半?yún)^(qū)間進行查找 } printf("無此數(shù)據(jù)"); system("pause");}(3)二叉排序樹的建立#include<stdio.h>#include<stdlib.h>typedefintdatatype;typedefstructnode{ datatypekey; structnode*lchild,*rchild;}bsnode;typedefbsnode*bstree;voidinsertbstree(bstree*t,datatypex){ bstreef,p; p=*t; while(p) { f=p; if(x<p->key) p=p->lchild; else p=p->rchild; } p=(bstree)malloc(sizeof(bsnode)); p->key=x; p->lchild=p->rchild=NULL; if(*t==NULL) *t=p; else { if(x<(f->key)) f->lchild=p; else f->rchild=p; } }bstreecreatbstree(bstreet){ datatypekey; scanf("%d",&key); while(key!=-1) { insertbstree(&t,key); scanf("%d",&key); } returnt;}voidinorder(bstreet){ if(t) { inorder(t->lchild); printf("%d",t->key); inorder(t->rchild);}} voidqorder(bstreet){if(t) { printf("%d",t->key); qorder(t->lchild); qorder(t->rchild);}}voidhorder(bstreet){ if(t) { horder(t->lchild); horder(t->rchild); printf("%d",t->key); } }intmain(){bstreet=NULL,p; printf("請輸入一個-1為結(jié)束標記的結(jié)點序列:\n"); p=creatbstree(t); printf("中序遍歷:"); inorder(p); printf("\n"); printf("先序遍歷:"); qorder(p); printf("\n"); printf("后序遍歷:"); horder(p); system("pause"); return0;}(4)哈希表的建立#include<stdio.h>#include<malloc.h>#defineINIT_MAXSIZE10typedefstructLnode{intdata;structLnode*next;}Lnode,*ListLink;//建立鏈表結(jié)點typedefstruct{intpos;ListLinkfirstnode;//建立數(shù)組結(jié)點}HashBox;typedefstruct{HashBoxHArrary[INIT_MAXSIZE];//建立哈希數(shù)組(哈希表的地址表頭)}HashArray;voidInitHashList(HashArray&l,intinput[],intaccount);//建立哈希表voidVistHashList(HashArray&l);//遍歷輸出哈希表intmain(void){intaccount=0,i=0,input[256];HashArrayl;printf("請輸入要插入哈希表元素的個數(shù):");scanf("%d",&account);printf("請輸入要插入哈希表的元素:");for(i=0;i<account;i++) {scanf("%d",&input[i]); }InitHashList(l,input,account);printf("\n哈希表如下:\n");VistHashList(l);return0;}voidInitHashList(HashArray&l,intinput[],intaccount)//建立哈希表{inti=0,j=0,pos=0;ListLinkq,p;charch='A';for(i=0;i<INIT_MAXSIZE;i++)//初始化哈希表頭 {l.HArrary[i].pos=ch++; l.HArrary[i].firstnode=NULL; }for(i=0;i<account;i++) {pos=input[i]%INIT_MAXSIZE;//計算元素地址 q=newLnode;//申請結(jié)點 q->data=input[i]; q->next=NULL; if(l.HArrary[pos].firstnode==NULL)//判斷當前地址表頭是否還沒有元素連入 l.HArrary[pos].firstnode=q; else {p=l.HArrary[pos].firstnode; while(p->next!=NULL) {p=p->next;//找到鏈表表尾 } p->next=q;//將要插入的結(jié)點接入表尾 } }}v

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
  • 6. 下載文件中如有侵權(quán)或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

最新文檔

評論

0/150

提交評論