In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly shows you "how to use linked lists in c # linear list". The content is easy to understand and clear. I hope it can help you solve your doubts. Let the editor lead you to study and learn this article "how to use linked lists in c # linear tables".
A single linked list is also a linked linear table in which the data elements in the linear table are stored in a set of storage units with arbitrary addresses. The data in the linked list is represented by nodes and linked by the next pointer to the next node. Compared with the sequential list, the linked list has the advantage of rapidly increasing and deleting nodes, and the random access efficiency of its nodes is low.
Header file:
/ * * Copyright:Yue Workstation * * FileName:LineTable.h * * Function: single linked list related data definition and function declaration * / # ifndef SINGLE_LIST_H # define SINGLE_LIST_H # include "global.h" typedef struct LNode {ElemType data Struct LNode * next;} LNode,*LinkList; int CreateSingleList (LinkList * Lpenint n); void PrintSingleList (LinkList L); int InsertSingleList (LinkList * L); int DeleteSingleList (LinkList * L); void DestroySingleList (LinkList * L); # endif
Source file:
/ * * Copyright:Yue Workstation * * FileName:SingleList.c * * Function: basic operation of single linked list * / # include ".. / Inc/SingleList.h "/ * * Function Name:CreateSingleList * * Function: Create a single linked list * * Parameter: l: single linked list header * n: single linked list length * * Return Value: 0 is returned successfully Failed to return-1 * / int CreateSingleList (LinkList * L drawing int n) {int I = 0 LinkList p1Magazine p2; * L = (LinkList) malloc (sizeof (LNode)); if (* L = = NULL) {perror ("malooc error\ n"); return-1;} (* L)-> data = 0; (* L)-> next = NULL; p1 = * L; p2 = * L; for (iTunes 1; idata = I; p2-> next = p1; p2 = p1 } p2-> next = NULL; (* L)-> data = n; return 0 } / * * Function Name:PrintSingleList * * Function: print single chain Table element * * Parameter: l: single linked table header * * Return Value: none * * / void PrintSingleList (LinkList L) {L = L-> next While (L) {printf ("% dmurf -", L-> data); L = L-> next;} putchar ('\ n'); return } / * * Function Name:InsertSingleList * * Function: in the I position Insert an element e * * Parameter: l: single linked list header * I: element location * e: element to be inserted * * Return Value: 0 is returned successfully Failed to return-1 * / int InsertSingleList (LinkList * Lfocus int I) ElemType e) {LinkList p1 = (* L)-> next LinkList p2 = (* L)-> next; int j = 1; while (p1 & & jnext; + + j;} if (! P1 | | j > imur1) {perror ("Insert position error,the parameter i is error!\ n"); return-1;} p2 = (LinkList) malloc (sizeof (LNode)); p2-> data = e; p2-> next = p1-> next; p1-> next = p2 (* L)-> data + = 1; return 0 } / * * Function Name:DeleteSingleList * * Function: in-process positioning Set and delete elements in single-linked list * * Parameter: l: single-linked list header * I: element location * e: element to be inserted * * Return Value: 0 is returned successfully Failed to return-1 * / int DeleteSingleList (LinkList * Lfocus int I) ElemType * e) {LinkList p1 = (* L)-> next LinkList p2 = NULL; int j = 1; while (p1 & & jnext; + + j;} if (! P1 | | j > = I) {perror ("Delete position error,the parameter i is error!\ n"); return-1;} p2 = p1-> next; p1-> next = p2-> next; * e = p2-> data; free (p2); (* L)-> data-= 1 Return 0 } / * * Function Name:GetSingleListLength * * Function: get single chain Table length * * Parameter: l: single linked list header * * Return Value: single linked list length * * * / int GetSingleListLength (LinkList L) {if (L = = NULL) {return-1 } return L-> data } / * * Function Name:DestroySingleList * * Function: destroy one Single linked list * * Parameter: l: single linked list header * * / void DestroySingleList (LinkList * L) {LinkList p1 = * L LinkList p2 = * L; while (p1! = NULL) {p2 = p1; p1 = p1-> next; free (p2);} * L = NULL; return;} above are all the contents of the article "how to use linked lists in c # linear tables". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.