Filename : stack.c
Author : lupingchen
Date : 2015.5.26
Content : empty.full. Push.pop
#include <stdio.h>
#include <stdlib.h>
Declaring a stack structure data type
typedef struct {
int* arr[];
int Len;
int top;
} Stack;
Judge Station full
int full (stack* PS);
Judge Stack Empty
int empty (stack* PS);
Stack operations
void push (stack* PS, int data);
Out stack operation
int pop (stack* PS);
int main (void)
{
return 0;
}
Judgment Stack Full
int full (stack* PS)
{
return ps->top = = ps->len;
}
Judge Stack Empty
int empty (stack* PS)
{
return 0 = = ps->top;
}
Stack operations
void push (stack* PS, int data)
{
Stack full
if (full (PS))
{
printf ("Stack full, fail into stack");
return-1;
}
Data compression stack
Ps->arr[ps->top] = data;
ps->top++;
}
Out stack operation
int pop (stack* PS)
{
Stack empty
if (empty)
{
printf ("Stack empty, out stack failed");
return-1; Stack empty Error
}
Data eject
Return ps->arr[--ps->top];
}