Joseph's cycle chain table implementation

zhaozj2021-02-16  147

#include

#include

#define number 13 // You can use the number of people's number #define next 8 // to determine the number of points of the number #define length sizeof (men) #define null 0

Struct Men {Int Number; Struct Men * Pmen;

Typedef struct men men;

/ ***************************************************** / / * Joseph Circulatory chain table realization * // **************************************************** * / void main () {men * pone = null, * ptwo = null, * PHEAD = NULL; int client

/ * * Create a ring chain list * / PHEAD = PONE = PTWO = (men *) malloc (length); PHEAD-> Number = 1; for (Client = 2; client <= number; client ) {Pone = (Men *) Malloc (length); ptwo-> pmen = pone; pone-> number = client; ptwo = pone;} Pone-> Pmen = PHEAD; / * * Operation * / PTWO = PHEAD; PONE = PTWO-> Pmen; While (Pone-> PMen! = PTWO) {for (Client = 0; Client Pmen;} // if (pone == PHEAD) // For single The head pointer to the linked list has not existed // PHEAD = PONE-> PMen; // else PTWO-> Pmen = Pone-> Pmen; PONE = NULL; Free (PONE); PONE = PTWO-> Pmen; PONE = Pone-> Pmen; PTWO = PTWO-> Pmen; / / Main State} Printf ("% D / N", Pone-> Number);

}

There is a power implementation for each bit:

#include #include

#define longth sizeof (men) #define null 0

Struct Men {Int Number; int code; struct men * pmen;

Typedef struct men men;

//// Joseph's circular chain table is implemented //

Void main () {men * pone = null, * ptwo = null, * pHead = null; int client; int number = 13; // Setting the default number int next = 3; // The selected number interval initial interval Number // // Printf ("Please enter the number of games:"); scanf ("% d", & number); // // Create an annular chain list // PHEAD = Pone = ptwo = (men *) Malloc (Length); if (PHEAD == NULL) {Printf ("head knot spatial allocation error!"); return;} // // Initial linked list, assignment to head node // pHEAD-> Number = 1 PRINTF ("Please enter the first bit of password:"); scanf ("% d", & phet-> code); for (client = 2; client <= number; client ) {Pone = (Men *) malloc Length); if (pone == null) {printf ("Space Assignment Error!"); Return;} PTWO-> PMEN = PONE; PONE-> Number = Client; Printf ("Please enter the password of the% D bit: ", client); scanf ("% d ", & pone-> code); PTWO = PONE;} Pone-> Pmen = PHEAD;

Printf ("/ N is selected in the order: / n"); // // Operation / PTWO = PHEAD; PONE = PTWO-> Pmen; While (Pone-> PMen! = PTWO) {for (client = 0; Client Pmen;} // if (pone == PHEAD) // For the head pointer of the one-way linked list, there is no presence // PHEAD = Pone-> Pmen; // Else PTWO-> Pmen = Pone-> Pmen; // Release Not Node // Printf ("% D", Pone-> Number; Next = Pone-> Code; PONE = NULL; free (PONE); PONE = PTWO-> PMen; PONE = PONE-> PMen; PTWO = PTWO-> PMen; // Main State} Printf ("% D", PTWO-> Number); Printf "/ N last left:% d / n", pone-> number);

转载请注明原文地址:https://www.9cbs.com/read-8437.html

New Post(0)