實(shí)驗(yàn)二 單向鏈表的操作_第1頁
實(shí)驗(yàn)二 單向鏈表的操作_第2頁
實(shí)驗(yàn)二 單向鏈表的操作_第3頁
實(shí)驗(yàn)二 單向鏈表的操作_第4頁
實(shí)驗(yàn)二 單向鏈表的操作_第5頁
已閱讀5頁,還剩3頁未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

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

文檔簡介

實(shí)驗(yàn)二單向鏈表的基本操作實(shí)驗(yàn)?zāi)康恼莆站€性表鏈?zhǔn)酱鎯?chǔ)的方法及其基本操作掌握將算法在VC++語言環(huán)境下實(shí)現(xiàn)的過程實(shí)驗(yàn)準(zhǔn)備復(fù)習(xí)線性表的定義,掌握鏈?zhǔn)酱鎯?chǔ)的方法及操作復(fù)習(xí)C語言中指針及結(jié)構(gòu)體的概念。定義方式VC++的編程環(huán)境實(shí)驗(yàn)內(nèi)容28,20,12,9,7,5,4,3,1在你自己的文件下,建立一個(gè)C語言程序LL.C,完成下列要求:定義一個(gè)單鏈表LLIST,按數(shù)據(jù)1,3,4,5,7,9,12,20,28的次序建立各結(jié)點(diǎn),形成單鏈表LLIST,然后按鏈表順序輸出九個(gè)結(jié)點(diǎn)的存儲(chǔ)單元地址和相應(yīng)的數(shù)值;建立一個(gè)插入函數(shù),將數(shù)據(jù)15作為結(jié)點(diǎn)按照從小到大的次序自動(dòng)插入到鏈表的相應(yīng)位置上,完成插入結(jié)點(diǎn)的操作,形成新的鏈表LLIST,然后輸出鏈表結(jié)點(diǎn)的存儲(chǔ)單元地址和相應(yīng)的數(shù)值;建立一個(gè)刪除函數(shù),將鏈表中第七個(gè)結(jié)點(diǎn)刪除,形成新的鏈表LLIST,然后輸出鏈表結(jié)點(diǎn)的存儲(chǔ)單元地址和相應(yīng)的數(shù)值;程序清單如下:#include<stdio.h>#include<stdlib.h>#include<malloc.h>#defineNULL0typedefstructnode{intdata;sttuctnode*next;}llist;main(){llist*h,*crtll(),*insll(),*dltll();outll();h=NULL;h=crtll(h);outll(h);h=insll(h);outll(h);h=dltll(h);outll(h);}llist*crtll(llist*h){}voidoutll(llist*h){llist*y,*p;inti=1;y=h;while(y!=NULL){printf(“N=%dAD=%xDATA=%dAD->=%x\n”,i,y,y->data,y->next);y=y->next;i++;}}llist*insll(llist*h){}llist*dltll(llist*h){}#include"stdafx.h"#include<stdio.h>#include"stdlib.h"typedefstructLnode{ intdata; structLnode*next;}Lnode,*Link;voidcreate_list(Link&L){ Linkp,current;inta[]={28,20,12,9,7,5,4,3,1},j=8;L=(Link)malloc(sizeof(Lnode));L->next=NULL;current=L;while(j>=0){p=(Link)malloc(sizeof(Lnode));p->data=a[j];current->next=p;current=p;j--;}p->next=NULL;}voidprintf_list(Linkhead){Linkp;p=head->next;while(p!=NULL){ printf("%d=",p); printf("%d\n",p->data);p=p->next;}}voidinsert(Link&L){ inta=0; intn; Linkcurrent,p,q;q=(Link)malloc(sizeof(Lnode));printf("輸入一個(gè)插入的數(shù)\n");scanf("%d",&n);q->data=n; p=L; current=L->next;while((current!=NULL)&&a==0) { if(q->data<current->data)a=1; else { p=p->next; current=current->next; } } p->next=q; q->next=current;}voidDelete(Link&L){ intn;printf("輸入一個(gè)刪除的數(shù)\n");scanf("%d",&n);Linkcurrent,p; p=L; current=L->next; while(n!=current->data) { p=p->next; current=current->next; } p->next=current->next; free(current);}voidmain(){Linkhead;create_list(head);printf_list(head);insert(head);printf_list(head);Delete(head);printf_list(head);}#include"stdafx.h"#include<stdio.h>#include"stdlib.h"typedefstructLnode{ intdata; structLnode*next;}Lnode,*Link;voidcreate_list(Link&L){ Linkp,current;inta[]={28,20,12,9,7,5,4,3,1},j=8;L=(Link)malloc(sizeof(Lnode));L->next=NULL;current=L;while(j>=0){p=(Link)malloc(sizeof(Lnode));p->data=a[j];current->next=p;current=p;j--;}p->next=NULL;}voidprintf_list(Linkhead){Linkp;p=head->next;while(p!=NULL){ printf("%d=",p); printf("%d\n",p->data);p=p->next;}}voidinsert(Link&L){ inta=0; intn; Linkcurrent,p,q;q=(Link)malloc(sizeof(Lnode));printf("輸入一個(gè)插入的數(shù)\n");scanf("%d",&n);q->data=n; p=L; current=L->next;while((current!=NULL)&&a==0) { if(q->data<current->data)a=1; else { p=p->next; current=current->next; } } p->next=q; q->next=current;}voidDelete(Link&L){ intn;printf("輸入一個(gè)要?jiǎng)h除的數(shù)的位置\n");scanf("%d",&n);Linkcurrent,p; p=L; current=L->next;for(inti=1;i<n;i++){ p=p->next;current=current->next;}p->next=current->nex

溫馨提示

  • 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ì)自己和他人造成任何形式的傷害或損失。

評(píng)論

0/150

提交評(píng)論