What are the operations of linked lists in C++ data structure
This article mainly shows you "what are the operations of linked lists in C++ data structures". The content is simple and clear. I hope it can help you solve your doubts. Next, let the editor lead you to study and learn the article "what are the operations of linked lists in C++ data structures".
First create a node
Typedef struct node {int date; struct node* next;} * PNODE; PNODE creatnode (int date) {PNODE newnode = (PNODE) malloc (sizeof (struct node)); assert (newnode); newnode- > next = NULL; newnode- > date = date; return newnode;} then create a statistics node attribute
Struct List {struct node* pronode;// this is just a type struct node*tailnode; int size;}; / / create a unified linked list attribute list / / to count the number of (size) nodes in the linked list / / head and tail are used to count the header and footer of the linked list struct List* creatlist () {struct List* list = (struct List*) malloc (sizeof (struct List)); assert (list) List- > pronode = NULL; list- > tailnode = NULL; list- > size = 0 alternative return list;} add nodes insert nodes by inserting headers
Void insertbyhead (struct List* list,int date) {PNODE newnode = creatnode (date); if (list- > size = = 0) {list- > pronode = list- > tailnode = newnode;} else {newnode- > next = list- > pronode; list- > pronode = newnode;} list- > size++ Delete node / / header delete void deletehead (struct List* list) {PNODE next = list- > pronode- > next; free (list- > pronode); list- > pronode = next;} / / delete void deletetail (struct List* list) {PNODE pmove = list- > pronode / / define a moving pointer / / to find the footer pointer if (list- > size = = 0) {printf ("cannot be deleted"); return;} while (pmove- > next! = list- > tailnode) {pmove = pmove- > next } pmove- > next = NULL;// the next pointer in front of the tail pointer points to null free (list- > tailnode); list- > tailnode = pmove;} these are all the contents of the article "what are the operations of linked lists in C++ data structures"? 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!