#include <stdio.h>#include<malloc.h>typedefstructnode{intkey; intnum; structNode *Next;} node,*plist;//Sequential CreationintInit (plist * L,intall_num) {plist p; inti; *l = P = (plist)malloc(sizeof(node)); P->num =1; P->next =NULL; for(i =2; I <= all_num; i++) {p->next = (plist)malloc(sizeof(node)); P= p->Next; P->num =i; P->next =NULL; } P->next = *m; return 1;}//ShowvoidPrint (plist L,intall_num) {plist p; inti =0; P=L; while(P && i!=all_num) {printf ("%d", p->num); P= p->Next; I++; } printf ("\ n");}//Enter keyvoidInput (plist L,intall_num) {plist p; inti =0; P=L; while(P && i!=all_num) {printf ("What is the key for%d?", p->num); scanf ("%d", &p->key); P= p->Next; I++; }}//Delete a nodevoidDelete (plist *L, plist p) {plist swap= *L; while(swap) {if(Swap->next = =p) {Swap->next = p->Next; if(*l = =p)*l = swap->Next; Free(P); Break; } Swap= swap->Next; }}intMainvoid) {plist L, p, swap; intAll_num, Kill_num, J, Count; Puts ("How many people circle around? "); scanf ("%d", &all_num); Puts ("initial key?"); scanf ("%d", &kill_num); if(!init (&L, All_num)) Puts ("initialization failed"); Puts ("initialization succeeded, number is given!"); Print (L, all_num); Puts ("Please enter your password"); Input (L, all_num); Puts ("Get started!"); Count=0; J=1;//Count off in turnSwap = P =L; while(Count! =all_num) { if(Kill_num = =j) {Print (L, All_num-count); printf ("starting from%d number key to%d\n", swap->num, kill_num); printf ("%d dequeue \ n", p->num); Kill_num= p->key; Swap= p->Next; Delete (&L, p); P=swap; J=1; Count++; Continue; } J++; P= p->Next; } if(Count = =all_num) printf ("ok\n");//L = p = swap = NULL; return 0;}
Data Structure-Joseph Ring