Source files section: #include <stdio.h> #include <string.h> #include <malloc.h>typedef int elemtype; #include " Delist.h "int main () {Dlnode head=null;instruction (head); return 0;} Header file section: typedef struct DLNODE {elemtype data;struct dlnode *prior; The Declaration of the node defines the struct Dlnode *next;} Dlnode,*dlnode;void init_dlist (Dlnode &head)//cyclic bidirectional initialization {head= (dlnode) malloc (sizeof (Dlnode)); head->prior= Head;head->next=head;} int Empty_dlist (Dlnode head)//double-empty {if (head->prior==head&&head->next==head) return 1;return 0;} void Insert_dlist (Dlnode *head,elemtype E)//head interpolation-bidirectional (new) {Dlnode p=null;p= (Dlnode *) malloc (sizeof (Dlnode)); Because it is a two-way loop linked list, there is no bidirectional problem with the IF (!p) {printf ("Sorry, there are not many other memory units being allocated!!! \ 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)//delete by location {Dlnode *p=null;int i=1;p=head->next;if (empty_dlist (head)) { printf ("Sorry, the list is empty and the delete operation cannot be completed!!! \ n "); return 0;} if (where>length_dlist (head) | | where<0) {printf ("Sorry, the location you deleted is not legal, please enter it again!!! \ n "); return 0;} while (I<where) {p=p->next;i++;} p->prior->next=p->prior->next->next;p->prior->next->prior=p->prior;printf ("Delete successful!!! \ n "); return p->data;} void Insearch_dlist (Dlnode head,elemtype E)//Find by Element {Dlnode *p=null;int len=1;if (empty_dlist (head)) {printf ("Sorry, the list is empty , unable to complete the find operation!!! \ n "); return;} P=head->next;while (P!=head) {if (p->data==e) {printf ("the element you are looking for is located in the first%d position of the linked list. \ n", Len); return;} p=p->next;len++;} printf ("Sorry, the element you are looking for does not exist, please enter it again!!! \ n "); return;} void Modify_dlist (Dlnode *head,elemtype where,elemtype e)//change by location {Dlnode *p=null;int len=1;p=head->next;while (len& Lt;where) {p=p->next;len++;} p->data=e;printf ("Change succeeded!\n"); return;} void Print_dlist (Dlnode head)//print operation {Dlnode p=head->next;if (EMpty_dlist (head) {printf ("Sorry, the list is empty and the print operation cannot be completed!!! \ n "); return;} while (head!=p) {printf ("%d", p->data);p =p->next;} printf ("\ n"); return;} void Destory_dlist (Dlnode head)//Destroy empty operation {Dlnode p=head->next;while (p!=head) {p->prior->next=p->next; P->next->prior=p->prior;p=head->next;} printf ("Destruction succeeded!\n");} void instruction (Dlnode head)//function function {int n,m,t,a,b,len1,index;printf ("\t\t1, initial operation \ n");p rintf ("\t\t2, new action \ n"); Why can't I define the head pointer here---because each time the function function is called, the head pointer is again initialized with printf ("\t\t3, delete operation \ n");p rintf ("\t\t4, find operation \ n");p rintf ("\t\ T5, change operation \ n ");p rintf (" \t\t6, destroy operation \ n ");p rintf (" \t\t7, seek long operation \ n ");p rintf (" \t\t8, print operations \ n ");p rintf (" \t\t9, exit program \ n ");p rintf ("Please enter the command you need to complete: \ n");d o{scanf ("%d", &n); if (n<1| | n>9) printf ("Sorry. The instruction number you entered is not valid. Please enter!!! again \ n ");} while (n<1| | N>9); switch (n) {case 1:init_dlist (head); Initialization operation printf ("Completed bidirectional list initialization, enter the number of elements you want to join!\n"), scanf ("%d", &n), while (n--) {int x;scanf ("%d", &x); insert_dlist (head,x);} printf ("Finished building table Operation!\n"); Break;casE 2://New operation if (!head) {printf ("Sorry, please complete the initialization before making the selection!!! \ n "); printf ("Please enter the number of elements you want to add!\n"), scanf ("%d", &n), while (n--) {int x;scanf ("%d", &x); Insert_dlist (head,x);} printf ("Add success!\n"); Break;case 3:printf ("Please enter the location of the node you want to delete: \ n"); scanf ("%d", &n);D elete_dlist (head,n); Delete operation Break;case 4:printf ("Please enter the element you are looking for: \ n"); scanf ("%d", &m); Insearch_dlist (head,m); Find Operation Break;case 5:if (Empty_dlist (head)) {printf ("Sorry, the list is empty and the change operation cannot be completed!!! \ n "); printf ("Please enter the queue location for the element you want to change: \ n"); Change Operation do{scanf ("%d", &a); if (a<1| | A>length_dlist (head)) printf ("Sorry. The element you entered is not in the area, please enter it again!!! \ n ");} while (a<1| | A>length_dlist (head));p rintf ("Please enter the modified value: \ n"); scanf ("%d", &b); Modify_dlist (head,a,b); Break;case 6:destory_dlist (head); Destruction Operation Break;case 7:len1=length_dlist (head); Returns the chain length operation printf ("Current chain queue Length is:%d\n", len1); Break;case 8:print_dlist (head); Print Operation Break;case 9://Exit Operation Return;dEfault:instruction (head); break;} Instruction (head);}
Read the full text of the copyright notice: This article for Bo Master original article, without Bo Master agreed not to reprint.
Report
- This article has been included in the following column:
1Article comments
-
-
-
Related articles recommended
-
data structure and algorithm six-way list and circular list in this chapter, you will learn to run the double link lists to run the Loop link list to apply the linked lists to solve programming problems today. Consider a demo sample where you need to display these numbers in descending order. How do I resolve this issue? Each node is linked to ... in the sequence.
- zhangchen124
- 2016-06-11 18:36
- 1943
-
How to create a circular doubly linked list the simplest way to loop a doubly linked list is to start with a circular list, which is simply to make the chain list end to end. Form a ring, because the general list is one-way, randomly given a node is not able to access the front of the link, which led to the limitation of the one-way list, circular linked list to a certain extent, to overcome this problem, through the table head ...
- lin19931006
- 2013-06-06 23:44
- 1537
-
C # embed a managed DLL in an EXE file C # embed a managed DLL in an EXE file recently developed a small program with WinForm, When using the Htmlagilitypack (for parsing HTML) and Newtonsoft.json (for parsing Json) The two libraries, because the compilation of the epigenetic ...
- Call_me_lzm
- 2016-05-25 20:59
- 1071
-
NET program how to prevent being injected (whole station Universal)
- Madeinjack
- 2008-03-22 10:13
- 199
-
How to use (register) the DirectShow interface DirectShow is a set of frequently used COM interface components, which are frequently used by igraphbuilder components. Imediacontrol,imediaevent interface. These three interfaces are not described first in this document. This article is mainly about how to use di ...
- Chinajiyong
- 2012-06-15 12:46
- 3362
-
Doubly linked list-C language version [Cpp]?view plaincopyprint? source file section:?? #include?? #include?? #include?? Typedef?int?...
- u012377333
- 2014-11-13 20:01
- 555
-
Introduction to Novice Programming (reprint) Part II introduction. This part is mainly about the introduction of programming, (to know a little bit of thought with a little common sense) "design." Coding. , and soft work (programming and thought) This chapter explains three ideas, primitives, abstractions, combinations, and so on. And the two important processes of software development, the related concept of software project, is the key to getting started with programming (to know a little field of mathematics) "Mathematics and Algorithms" (programming and mathematics) the computer is the whole structure of mathematics. and computer platform implementation. Algorithm design, architecture is closely related,. Really going deep into programming, ... The study of mathematics is a must. Don't be a match.
- Weiyinchao88
- 2012-01-22 10:26
- 1803
-
Two-way circular link list program (C language version) bidirectional cyclic link list program (C language edition)?? 2006-08-27 01:49:50|?? Category: Software Programming | font size? Subscribe to Http://blog.163.com/huzuhu ...
- Quannii
- 2013-03-19 01:13
- 457
-
Generic Double circular linked list-Universal bidirectional cyclic link List C language implementation Generic Double circular linked list-Universal bidirectional circular List C language implementation CHEUNGM INE two-way loop linked list is the most basic of computer data structure
- Cloudtech
- 2010-09-18 20:12
- 332
-
Single-linked list operation C language March 24, 2009 13:04 Slyar <span style= "COLOR: #297
- Blogdown
- 2009-09-06 18:51
- 75
-
-
Small_white + attention
-
Original
-
-
Fans
One
-
Like
-
0
- buffer and cache with buffers and cached analysis
- on the relation of complement and complement
- Linux Log Basics
- MFC Usage Tips (How to delete a class completely)
many other articles
Online Courses
-
-
Utm_source=blog7 "target=" _blank ">" Live "Machine learning & Data Mining 7 weeks training--Wei Chi
-
-
Utm_source=blog7 "target=" _blank ">" Package "System integration project manager Smooth customs clearance--Xu Bong
- folder
-
- like to cancel like
- Collection
- share Weibo QQ
Collection Assistant Bad news report