Stack

xiaoxiao2021-03-06  71

/ // / Set a sequential stack SS and a chain stack LS to implement the following: // Enter a number of positive intensions from the keyboard (in the end sign of the input negative), press in SS. // then display the value of the inverse sequence and the positive order of the input data (can be used with the value of the display positive order using LS assist) // ** screen display, as shown in the example: // 3 4 6 8 9 2 -1 // 2 9 8 6 4 3 // 3 4 6 8 9// A stack algorithm implementation can refer to the following part of the teaching plan, // Use the same function name to the PUSH operation of the order stack and the chain stack, // (POP Operation is also the same) Note: The characteristics of function overload in C . ////

#include #include

#define Length 15

Typedef struct node * ptrtonode; struct node {int element; pTRTONODE NEXT;

PTRTONODE POP (PTRTONODE TOP (INT Element); PTRTONODE PUSH; Void Pop (INT * TOP, INT Client); int Push (int * TOP);

Void main (void) {// ss // int s [length]; int * top2; int * base2; int number; top2 = base2 = ss; while (1) {scanf ("% d", & number); IF ((TOP2 - BASE2) next = null; base-> element = NULL; While (1) {if (TOP2> = Base2) {ELEMENT = Push (TOP2); Printf ("% D", ELEMENT); TOP2--;} else // the first number break; top = pop (Top, ELEMENT }

Printf ("/ n"); while (1) {if (top! = base) {Printf ("% d", top-> element); TOP = Push (TOP);} else break;

}

//// sl Function // PTRTONODE POP (PTRTONODE TOP (INT Element) {PTRTONODE Client; Client = (PTRTONODE) ​​Malloc (SizeOf (Node)); Client-> Next = Top; TOP = Client; TOP-> Element = ELEMENT; RETURN TOP;

PTRTONODE PUSH (PTRTONODE TOP) {PTRTONODE Client; Client = Top; Top = Top-> Next; Free (Client); // Free Do The Two Thing Free The Space and Set The Client Null Return Top;} //// SS Founction // Void Pop (INT * TOP, INT Client) {* (TOP) = Client;}

INT Push (int * TOP) {RETURN * (TOP); * (TOP) = null;}

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

New Post(0)