Single-chain table operations
In order to prepare for the test, I wrote several single-chain table operations, including chain creation, chain deletion, insertion of nodes, deletion of nodes, and reverse order of linked lists.
Struct node {int data; struct node * Next;}; struct node * create_list () {struct node * P, * q, * h; int I; P = H = (struct node *) malloc (sizeof (struct node); H-> DATA = 6; for (I = 0; I <5; I ++) {q = (struct node *) malloc (sizeof (struct node); q-> DATA = I; P-> next = Q; P = p-> next; Q = NULL;} return h;} void free_list (struct node * h) {struct node * P = H; struct node * q; while (p) {q = P; P = p-> next; free (q) ;}} void PRI Nt_list (const struct node * h) {struct node * P = H; while (p) {printf ("% d", p-> data ); P = p-> next;} printf ("\ n ");} /* Insert a node with the value of data at the POs node */struct node * insert_elem (struct node * H, int POs, int data) {struct node * P, * q; P = H; q = (struct node *) malloc (sizeof (struct node); q-> DATA = data; /* insert to 0th locations */If (Pos = 0) {q-> next = H; H = Q ;} else {/* insert to position after 0 */while (-- POS)/* locate to the previous node of the insertion point */P = p-> N EXT; q-> next = p-> next; P-> next = Q;} return h ;} /* Delete the second POS node */struct node * delete_pos (struct node * H, int POS) {struct node * P, * q; q = NULL; P = h; /* determine whether the linked list is empty */If (! H) return NULL;/* Delete the 0th nodes */If (Pos = 0) {H = H-> next;} else {While (pos --) {/* locate the POs node */q = P; P = p-> next;} Q-> next = p-> next;} Free (P ); return h;}/* Delete the first node with data in the linked list */struct node * delete_elem (struct node * H, int data) {struct node * P, * Q, * t; q = P = H;/* determine whether the linked list is empty */If (! H) return NULL;/* in the traversal table, locate the node with the value of data */while (p-> data! = Data & P-> next) {q = P; P = p-> next;} If (p-> DATA = data) {If (P = H) /* determine whether the node is a header node */h = H-> next; elseq-> next = p-> next; free (p);} return h ;} /* reverse list */struct node * reverse_list (struct node * h) {struct node * P, * t, * q; P = H; t = q = NULL; while (p) {T = p-> next; P-> next = Q; q = P; P = T;} return Q ;}