<html>

來源:互聯網
上載者:User

標籤:timeout   軟體開發   elf   close   target   通用   one   演算法   closed   

源檔案部分:#include<stdio.h>#include<string.h>#include<malloc.h>typedef int Elemtype;#include"Delist.h"int main(){Dlnode head=NULL;instruction(head);return 0;}標頭檔部分:typedef struct DLnode        {Elemtype data;struct DLnode *prior;    //節點的聲明定義struct DLnode *next;}DLnode,*Dlnode;void Init_Dlist(Dlnode &head)    //迴圈雙向初始化 {head=(Dlnode)malloc(sizeof(DLnode));head->prior=head;head->next=head;}int Empty_Dlist(Dlnode head)       //雙向判空{if(head->prior==head&&head->next==head)return 1;return 0;}void Insert_Dlist(DLnode *head,Elemtype e)   //頭插法-雙向(新增){Dlnode p=NULL;p=(DLnode *)malloc(sizeof(DLnode));            //由於是雙向迴圈鏈表,所以不存在雙向的那個問題if(!p){printf("對不起,已無很多其它的記憶體單元得到分配!!!\n");return ;}p->data=e;p->next=head->next;p->next->prior=p;p->prior=head;//printf("*%d*\n",head->next);head->next=p;}int Length_Dlist(Dlnode head){DLnode *p=NULL;int len=0;if(Empty_Dlist(head))return 0;p=head->next;while(p!=head){len++;p=p->next;}return len;}int Delete_Dlist(DLnode *head,Elemtype where)        //按位置刪除{DLnode *p=NULL;int i=1;p=head->next;if(Empty_Dlist(head)){printf("對不起,鏈表是空的,無法完畢刪除操作!!!\n");return 0;}if(where>Length_Dlist(head)||where<0){printf("對不起,你刪除的位置是不合法的,請又一次輸入!!!\n");return 0;}while(i<where){p=p->next;i++;}p->prior->next=p->prior->next->next;p->prior->next->prior=p->prior;printf("刪除成功!!!\n");return p->data;}void Insearch_Dlist(Dlnode head,Elemtype e)      //按元素尋找  {DLnode *p=NULL;int len=1;if(Empty_Dlist(head)){printf("對不起,鏈表是空的,無法完畢尋找操作!!!\n");return ;}p=head->next;while(p!=head){if(p->data==e){printf("你要尋找的元素位於鏈表的第%d個位置上.\n",len);return ;}p=p->next;len++;}printf("對不起,你要尋找的元素不存在,請又一次輸入!!!\n");return ;}void Modify_Dlist(DLnode *head,Elemtype where,Elemtype e)    //按位置改動{DLnode *p=NULL;int len=1;p=head->next;while(len<where){p=p->next;len++;}p->data=e;printf("改動成功!\n");return ;}void Print_Dlist(Dlnode head)          //列印操作{Dlnode p=head->next;if(Empty_Dlist(head)){printf("對不起,鏈表是空的,無法完畢列印操作!!!\n");return ;}while(head!=p){printf("%d ",p->data);p=p->next;}printf("\n");return ;}void Destory_Dlist(Dlnode head)            //銷毀清空操作{Dlnode p=head->next;while(p!=head){p->prior->next=p->next;p->next->prior=p->prior;p=head->next;}printf("銷毀成功!\n");}void instruction(Dlnode head)             //功能函數 {int n,m,t,a,b,len1,index;printf("\t\t1、初始操作\n");printf("\t\t2、新增操作\n");              //為什麼不能在這裡定義head指標---由於每次調用功能函數後,head指標又被又一次初始化了    printf("\t\t3、刪除操作\n");printf("\t\t4、尋找操作\n");printf("\t\t5、改動操作\n");printf("\t\t6、銷毀操作\n");printf("\t\t7、求長操作\n");printf("\t\t8、列印操作\n");printf("\t\t9、退出程式\n");printf("請輸入你所須要完畢的指令:\n");do{scanf("%d",&n);if(n<1||n>9)printf("對不起。你輸入的指令編號是無效的。請又一次輸入!!!\n");}while(n<1||n>9);switch(n){case 1:Init_Dlist(head);            //初始化操作printf("已完畢雙向鏈表初始化,請輸入你要加入的元素個數!\n");scanf("%d",&n);while(n--){int x;scanf("%d",&x);Insert_Dlist(head,x);}printf("完畢建表操作!\n");break;case 2:                                  //新增操作if(!head){printf("對不起,請先完畢初始化操作再做該選擇!!!\n");break;}printf("請輸入你要加入的元素個數!\n");scanf("%d",&n);while(n--){int x;scanf("%d",&x);Insert_Dlist(head,x);}printf("增添成功!\n");break;case 3:printf("請輸入你所要刪除的節點的位置:\n");scanf("%d",&n);Delete_Dlist(head,n);                             //刪除操作break;case 4:printf("請輸入你所要尋找的元素:\n");scanf("%d",&m);Insearch_Dlist(head,m);                       //尋找操作 break;case 5:if(Empty_Dlist(head)){printf("對不起,鏈表是空的,無法完畢改動操作!!!\n");break ;}printf("請輸入你要更改的元素隊列位置:\n");          //改動操作 do{scanf("%d",&a);if(a<1||a>Length_Dlist(head))printf("對不起。你所輸入的元素位置不在地區內,請又一次輸入!!!\n");}while(a<1||a>Length_Dlist(head));printf("請輸入改動後的值:\n");scanf("%d",&b);Modify_Dlist(head,a,b);break;case 6:Destory_Dlist(head);            //銷毀操作 break;case 7:len1=Length_Dlist(head);             //返回鏈長操作 printf("當前鏈隊列的長度為:%d\n",len1);break;case 8:Print_Dlist(head);        //列印操作 break;case 9:                   //退出操作 return;default:instruction(head);break;}instruction(head);}

閱讀全文 著作權聲明:本文為博主原創文章,未經博主同意不得轉載。 舉報
  • 標籤:
  • 資料結構 /
  • q=c語言&t=blog" target="_blank">c語言 /

  • 迴圈雙向鏈表 /
  • 設計 /
  • 本文已收錄於下面專欄:
1條評論
相關文章推薦
資料結構與演算法之六 雙向鏈表和迴圈鏈表 在本章中,你將學習:運行雙連結清單運行迴圈連結清單應用連結清單以解決編程問題如今。考慮一個示範範例,您須要以降序的方式顯示這些數字。怎樣解決此問題?每個節點連結到序列中的...
  • zhangchen124
  • 2016-06-11 18:36
  • 1943
迴圈雙向鏈表的建立方法 最簡單的迴圈雙向鏈表 首先講迴圈鏈表,簡單來說就是讓鏈表首尾相連。形成一個環,由於一般的鏈表都是單向的,隨意給出的一個節點是不能訪問前面的鏈節,這就導致了單向鏈表的局限性,迴圈鏈表從一定程度上來說就攻克了這一問題,通過表頭...
  • lin19931006
  • 2013-06-06 23:44
  • 1537
C#將託管DLL嵌入exe檔案 C#將託管DLL嵌入exe檔案近期用winForm開發一個小程式,當中用到了HtmlAgilityPack(用於解析html)和Newtonsoft.Json(用於解析json)這兩個庫,因為編譯後生...
  • call_me_lzm
  • 2016-05-25 20:59
  • 1071
Net程式怎樣防止被注入(整站通用)
  • MadeInJack
  • 2008-03-22 10:13
  • 199
怎樣使用(注冊)DirectShow介面 DirectShow是一組經常使用的COM介面組件,當中經常使用的組件有IGraphBuilder。IMediaControl,IMediaEvent介面。這三個介面在本文先不介紹。本文主要是講講怎樣使用Di...
  • Chinajiyong
  • 2012-06-15 12:46
  • 3362
雙向鏈表-C語言版 [cpp]?view plaincopyprint?源檔案部分:??#include??#include??#include??typedef?int?...
  • u012377333
  • 2014-11-13 20:01
  • 555
編程新手導論(轉載) 第二部分 導論。這一部分主要是關於編程的導論,(要懂得一點思想具備一點常識)《設計。編碼。,與軟工》(編程與思想)這一章解釋了三種思想,原語,抽象,組合,。和軟體開發的二個重要過程,,軟體project的相關概念,是編程入門的關鍵(要懂得一點領域內的數學)《數學與演算法》(編程與數學)電腦整個就是架構在數學上的。跟電腦平台實現。演算法設計,,架構密切相關,。真正要深入編程,。。對數學的學習是必須的,。千萬不要相
  • weiyinchao88
  • 2012-01-22 10:26
  • 1803
雙向迴圈鏈表程式(C語言版) 雙向迴圈鏈表程式(C語言版)??2006-08-27 01:49:50|??分類:?軟體編程|字型大小?訂閱http://blog.163.com/huzuhu...
  • quannii
  • 2013-03-19 01:13
  • 457
Generic double circular linked list - 通用雙向迴圈鏈表C語言實現 Generic double circular linked list - 通用雙向迴圈鏈表C語言實現cheungmine雙向迴圈鏈表是電腦資料結構裡面最基礎
  • cloudtech
  • 2010-09-18 20:12
  • 332
單鏈表的操作C語言版 2009年3月24日 13:04 Slyar <span style="color: #297
  • BlogDown
  • 2009-09-06 18:51
  • 75
Small_White +關注
原創
30
粉絲
11
喜歡
0
  • buffer和cache與buffers和cached分析
  • 論補數和補碼的關係
  • linux日誌基礎知識
  • MFC的提示(怎樣徹底刪除一個類)
很多其它文章 線上課程

utm_source=blog7" target="_blank">【直播】機器學習&資料採礦7周實訓--韋瑋

utm_source=blog7" target="_blank">【套餐】系統整合專案管理project師順利通關--徐朋

  • 檔案夾
  • 喜歡 取消愛好
  • 收藏
  • 分享 微博 QQ
收藏助手 不良資訊舉報

<html>

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.