a interface to stack that implement use the fixed array.

来源:互联网 发布:卖家怎样加入淘宝客 编辑:程序博客网 时间:2024/05/16 07:45

/* a interface to stack that implement use the fixed array.
   date: 2006.11.23
   author: dongshuiluo
   complier: dec-c++ 4.9.9.2
*/

#ifndef DONGSHUILUO_STACK_H
#define DONGSHUILUO_STACK_H

typedef struct StackItem StackItem;
typedef struct Stack Stack;

struct StackItem    /* user should modify it */
{
    int a;
};

struct Stack
{
    StackItem *items;
    unsigned int top;
    unsigned int capacity;
};

/* usage:  initlize a stack use the size and before you use it .
   pre:    size >= 0
   post:   return a stack pointer, if fail then return NULL.
*/
extern Stack *CreatStack( unsigned int size );

/* usage: add a new element to a exist stack.
   pre:   the stack has been created and the stack not full.
   post:  return 0 if success otherwise -1.
*/
extern int push( StackItem item, Stack *stack );

/* usage: get the top element from a exist stack.
   pre:   the stack has been created and the stack is not empty.
   post:  the element's will be stored in *item,
          and return 0 if success otherwise -1.
*/
extern int top( StackItem *item, Stack *stack );

/* useage: remove the top element from a exist stack.
   pre:    the stack has been created and the stack is not empty.
   post:   the top element will be removed,
           and return 0 if success otherwise -1.
*/          
extern int pop( Stack *stack );

/* usage: judge the exist stack is empty or not.
   pre:   the stack has been created.
   post:  return 1 if the stack is empty otherwise 0.
*/
extern int StackEmpty( Stack *stack );

/* usage: judge the exist stack is full or not.
   pre:   the stack has been created.
   post:  return 1 if the stack is full otherwise 0.
*/
extern int StackFull( Stack *stack );

/* usage: get the element's number of the stack.
   pre:   the stack has been created.
   post:  the stack's size as return value.
*/   
extern unsigned int StackSize( Stack *stack );

/* usage: get the stack's capacity.
   pre:   the stack has been created.
   ppst:  the stack's capacity as a return value.
*/
int StackCapacity( Stack *stack );
  
/* usage: make the stack become to a empty stack.
   pre:   the stack has been created.
   post:  the stack is empty.
*/
extern int MakeEmpty( Stack *stack );

/* usage: depose a stack when you nerver use it again.
   pre:   the stack has been created.
   post:  you can not use the stack again.
*/
extern int DesposeStack( Stack *stack );

#endif
 

原创粉丝点击