a interface to stack that implement use the fixed array.

/* 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
 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值