ARTICLE DETAIL

资讯详情

深耕网站建设、视觉设计与SEO优化的一线实战洞察。

栈的基本函数

栈的基本函数

include

include<stdlib.h>

define MaxSize

using namespace std;
typedef int ElemType;

typedef struct
{ElemType data[MaxSize];int top;
}SqStack;void InitSqStack(SqStack *&s)
{s=(SqStack *)malloc(sizeof(SqStack));s->top=-1;
}void DestoryStack(SqStack *&s)
{free(s);
}bool StackEmpty(SqStack *&s)
{return (s->top==-1);
}bool Push(SqStack *&s,ElemType e)
{if (s->top==MaxSize-1)return false;s->top++;s->data[s->top]=e;return true;
}bool Pop(SqStack *&s,ElemType &e)
{if(s->top==-1){return false;}e=s->data[s->top];s->top--;return true;
}bool GetTop(SqStack *&s,ElemType &e)
{if(s->top==-1){return false;}e=s->data[s->top];return true;
}

int main(){

return 0;

}

返回列表