/***************************************************** Copyright (C), 2014-2015, lighting Studio.
Co., Ltd. File name:Author:Jerey_Jobs version:0.1 Date:Description:Funcion List: ****************************************
/#include <stdio.h> #include <stdlib.h> #define MAX struct stack{int Stack_text[max];
int top;//array element (stack element) subscript};
typedef struct stack stack;
Enum Return_result{push_ok,push_no,full_ok,full_no,empty_ok,empty_no};
void Is_malloc_ok (Stack *stack)//Whether to assign success {if (stack = NULL) {printf ("malloc error!\n"); Exit (-1);//End process} void Creat_stack (Stack **stack)/Allocate space {(*stack) = (stack*) malloc (sizeof (stack);/Allocate Space is_ma
LLOC_OK (*stack); } void Init_stack (Stack *stack)//Initialize {stack->top =-1;//top assignment is-1, position on stack top} int is_full (stack *stack)/check stack full {if (s)
Tack->top = = Max) return FULL_OK;
else return full_no; int push_stack (stack *stack,int num)/into stack operation {if (is_full (stack) = = FULL_OK)//Stack full {printf ("thE stack is full!\n ");
return push_no; }//Stack not full stack->top++; Top is-1 finished top is 0 stack->stack_text[stack->top] = num;
Value is written to return PUSH_OK;
The int is_empty (stack* stack)//Determines whether the stack is empty {if (Stack->top = 1) {return EMPTY_OK;
return empty_no;
} int pop_stack (stack *stack)/out stack operation {if (is_empty (stack) = = EMPTY_OK)/stack Empty {printf ("stack is empty\n");
return EMPTY_OK;
else//Stack not empty stack content return empty_no;
int main () {stack* Stack;
int i; Creat_stack (&stack);//Create Stack init_stack (stack)//stack initialization for (i = 0;i < max;i++)//Stack count {if (Push_stack + 1)
= = PUSH_OK)//into the stack printf ("Successful!\n into the stack");
else printf ("Stack failed!\n"); for (i = 0;i < max;i++)//out stack count {if (pop_stack (stack) = = empty_no)/out stack to determine whether stack is empty {printf ("num =%d\n",stack->
Stack_text[stack->top]);
stack->top--;//forward} else {printf ("Stack empty!\n");
} return 0;
}