#include <iostream>//#include <time.h>//#include <stdlib.h>using namespace std; #define OK 1#define TRUE 1#define FALSE 0#define ERROR 0typedef int status;//Returns the status value typedef int ELEMTYPE;//node data type//per node structure typedef struct Stacknode{elemtype the data;//node's data stacknodeptr next;//refers to the pointer to a node down.} STACKNODE,*STACKNODEPTR;//TOP data structure typedef struct LINLSTACK{STACKNODEPTR top;//pointer to the top element of the stack. int count;//number of elements} linlstack;//into stack operation//value e pressed into stack L status Push_stack (Linlstack *l,elemtype e) {stacknodeptr p;//define a pointer to node p= (stacknodeptr) malloc (Stacknode);//Open dynamic memory p->next=l->top;//the pointer of the node to the original stack-top element p->data=e;//assigns the value of E to the current top-of-stack element l->top =p;//the top pointer to the current stack top element l->count++;//The value of the Count plus a return OK;} Out of stack operation//the stack top element in the stack L pops up to E in status Pop_stack (Linlstack *l,elemtype &e) {if (l->count==0)//If stack is empty the stack returns an error indicating return errors; e=l->top->data;//the data for the top element of the stack to estacknodeptr p;//Define a node pointer p=l->top;//pointer to the original top element of the stack l->top=l->top-> next;//the original stack top element below the address of an element to the topl->count--;//count minus one free (p);//The element that pops up the stack frees the memory space return OK; int main () {sysTEM ("pause"); return 1;}
The chain storage structure of the stack of the big talk data structure