C言語実現:優(欠)美(殴る)双方向順序スタック
9055 ワード
#include
#include
#define MaxSize 10
typedef struct DEndStack
{
int top[2];
int data[MaxSize];
} DEndStack;
struct DEndStack *InitStack()
{
struct DEndStack *S = (struct DEndStack *)malloc(sizeof(struct DEndStack));
S->top[0] = -1;
S->top[1] = MaxSize;
return S;
}
//i
int push(struct DEndStack *S, int x, int i)
{
//
if (S->top[0] == S->top[1] - 1) return 0;
//
else
if (i == 0) S->data[++(S->top[i])] = x;
else S->data[--(S->top[i])] = x;
return 1;
}
int pop(struct DEndStack *S, int i)
{
int res;
if (i == 0)
if (S->top[i] == 0) return 0;
else res = S->data[S->top[i]--];
else
if (S->top[i] == MaxSize) return 0;
else res = S->data[S->top[i]++];
return res;
}
int main()
{
struct DEndStack *S = InitStack();
push(S, 1, 1);
pop(S, 1);
return 0;
}