- Full table creation for single-linked lists
- Declares a node p and counter variable i
- Initialize an empty list L
- The pointer to the head node of L points to null, which is a single linked list that creates a lead node
- The assignment and insertion of successive nodes in a cyclic implementation
- Head interpolation: Starting with an empty table, generating a new node, reading the data into the data field of the new node, and inserting the new node into the table header of the current list until the end position. Simply put the newly added element in the first position after the table header
- Let the next point of the new node go to the head node.
- Then point the table header next to the new node.
voidCreatelisthead (linklist *l,intN) {linklist p; inti; Srand (Time (0));//Initialize random number seed*l = (linklist)malloc(sizeof(Node)); (*L)->next =NULL; for(i =0; I < n; i++) {p= (linklist)malloc(sizeof(Node)); P->data = rand ()% -+1; P->next = (*l)Next}}
3. Setting up single-link list by tail interpolation
voidCreatelisttail (linklist *l,intN) {linklist p,r; inti; Srand (Time (0));//Initialize random number seed*l = (linklist)malloc(sizeof(Node)); R= *L; for(i =0; I < n; i++) {p= (Node *)malloc(sizeof(Node)); P->data = rand ()% -+1; R->next =p; R=p; } R->next =NULL;}
Data structure and algorithm learning notes (iv)