Cat eating mouse problem

zhaozj2021-02-16  54

#define len sizeof (struct catmouse)

Struct Catmouse

{Int Num;

Struct CATMOUSE * NEXT;

}

void main ()

{struct catmouse * head, * p, * q;

INT N, M, I, J;

Int a [7];

Printf ("/ NENTER THE ANTEGER:");

Scanf ("% d", & n);

P = q = (struct catmouse *) malloc (len);

P-> NUM = 1;

HEAD = P;

For (i = 2; i <= n; i ) // establish a loop chain list

{P = (struct catmouse *) malloc (len);

P-> Num = i;

Q-> next = P;

Q = P;

}

Q-> next = Head;

P = q = head; // Point to the header node, each node sequentially cut out the mouse

For (i = 0; i

{

P = Q-> NEXT;

Q = P;

P = Q-> NEXT;

Q-> next = p-> next;

Free (p);

}

Printf ("/ n last number is:% D", P-> Num); / / Result

Getch ();

}

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

New Post(0)