Joseph ring problem procedure

zhaozj2021-02-16  67

#include #include

Typedef struct lnot {int data; intend; slate lnot;} lnode, * list;

/// // Auxiliary function lnode * createnode () {lnode * p = (lnode *) malloc (sizeof (lnode)); if (! P) {exit (0);} return p;}

Void destoryNode (lnode * p) {free (p);}

List listinsertfront (list l) {lnode * p = cretenode (); p-> next = L; return p;}

Lnode * listremovenext (list prev) {lnode * p = prev-> next; prev-> next = p-> next; return p;}

///// creation process List create, {list tail, l = cretenode (); l-> data = 1; l-> code = ncount;

Tail = L; // Printf ("Create 0th, No.% D, Irself in% PN", L-> Code, L); for (int i = 1; i code = ncount - i; l-> DATA = 0; // printf ("Create the% D, number is% D, yourself in% P, the next is% PN", i, L-> Code, L, L-> Next);} tail-> next = L; // ring table

Return L;

// Input Process Void InitringQueue (List L, Int Ncount) {List BEGIN = L; INT J = 0;

While (j! = ncount) {printf ("Input the parameters of the% D", J 1); scanf ("% d", & begin-> data); if (begin-> data> 0) {begin = Begin-> Next; J ;}}}

// Delete Process List RemoveFromqueue (List L, Int Nidx) {List BEGIN = L, End = L-> Next; Int IDX = NIDX;

While (begin! = End) {// printf ("From the first% D number", becoming-> code, idx); / / Find N-1, for (int i = 0 i code); begin = begin-> next;} // delete the nth lnode * p = ListremoveNext (Begin); // Remove the next N-value IDX = P-> Data; DestoryNode (P); End = Begin-> Next;} return begin;

INT main () {int N = 0; Printf ("Input Link Location Length"); Scanf ("% D", & n); if (n <= 0) {RETURN 0;} List L = CreateringQueue (n); inIntringQueue (L, N); Lnode * last = RemoveFromqueue (L, 3);

Printf ("Last IS% D, DATA IS% D", Last-> Code, Last-> DATA); RETURN 0;}

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

New Post(0)