/ // / 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
#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)
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;}