码迷,mamicode.com
首页 > 其他好文 > 详细

栈的顺序存储和基本实现

时间:2014-10-09 01:30:27      阅读:280      评论:0      收藏:0      [点我收藏+]

标签:style   blog   color   io   os   ar   sp   div   c   

#include<iostream>
#include<cstring>
#include<cstdlib>
#define maxsize 1000
using namespace std;
//顺序结构
typedef struct 
{
    int data[maxsize];
    int top;
}SqStack;
//初始化栈
void initStack(SqStack *&s)
{
    s = new SqStack;
    s->top = -1;//空栈
}
void Clearstack(SqStack *&s)
{
    delete s;
}
//求栈的长度
int StackLength(SqStack *s)
{
    return (s->top+1);
}
//判断栈是否为空
int StackEmpty(SqStack *s)
{
    return (s->top == -1);
}
//进栈
int push(SqStack *&s,int e)
{
    if (s->top == maxsize - 1)//栈满的情况,栈上溢出
        return 0;
    s->top++;
    s->data[s->top] = e;//将e插进栈顶
    return 1;
}
//出栈
int  pop(SqStack *&s,int e)
{
    if (s->top == -1)//空栈情况,栈下溢出
        return 0;
    e= s->data[s->top];
    s->top--;
    return 1;
}

 

栈的顺序存储和基本实现

标签:style   blog   color   io   os   ar   sp   div   c   

原文地址:http://www.cnblogs.com/tong1487/p/4011759.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!