Repeat this code because it is worth learning.
1. For the linked list, you can easily insert data into the header, but if you keep a tail node, you can easily insert nodes at the end.
2. You do not need to define a pointer to retain the parent node of the node you want to delete. You only need to set a few pointer values. For example, in the Code: If (COUNT = stride-1)
Sample Code:
# Include <stdio. h> struct monkey {int ID; monkey * Next;}; int main (INT argc, char * argv []) {monkey * link, * monkey, * lastmonkey; int totalmonkeys, stride, count; printf ("Please input the numbers of monkeys: \ n"); scanf ("% d", & totalmonkeys); printf ("Please input a number for striding: \ n "); scanf (" % d ", & STRIDE); link = NULL; For (INT I = 0; I <totalmonkeys; I ++) {monkey = new monkey; monkey-> id = I + 1; if (link = Null) {link = lastmonkey = monkey;} else {lastmonkey-> next = monkey; lastmonkey = monkey ;}} lastmonkey-> next = link; Count = 1; printf ("monkey team sequence:"); While (Link! = NULL) {If (Link-> next = link) {printf ("% 4D \ n", link-> ID); Delete link; break ;} if (COUNT = stride-1) {monkey = link-> next; Link-> next = monkey-> next; printf ("% 4D", monkey-> ID ); delete monkey; monkey = NULL; Count = 0;} link = link-> next; count ++;} return 0 ;}