栈的顺序存储,所谓的顺序栈

2014-11-23 23:33:59 · 作者: · 浏览: 3
与线性表类似栈也有两种存储结构,即顺序存储结构和链表存储结构。栈的顺序存储结构亦称为顺序栈,它是运算受限的顺序表。
#pragma once

class stack
{
public:
	stack(void);
	stack(int maxsize);
	~stack(void);
private:
	int *m_list;
	int m_maxsize;
	int m_top;
public:
	bool push(int value);
	bool pop();
	bool top(int *value);
	bool empty();
	bool full();
	int size();
	void output();
};

#include "StdAfx.h"
#include "stack.h"


stack::stack(void)
{
	m_maxsize = 10;
	m_list = new int[m_maxsize];
	for(int i=0; i
// sequstack.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include "stack.h"

int _tmain(int argc, _TCHAR* argv[])
{
	stack mystack(10);

	//入栈 0 --- 9
	/*for(int i=0; i<10; i++)
	{
		mystack.push(i);
	}
	
	if (mystack.full()) printf("stack is full\n");
	printf("stack size=%d\n", mystack.size());

	//出栈
	for(int i=0; i<10; i++)
	{
		int value = 0;
		mystack.top(&value);
		mystack.pop();
		printf("pop value=%d\n", value);
	}
	if (mystack.empty()) printf("stack is empty\n");
	printf("stack size=%d\n", mystack.size());*/

	mystack.push(8);
	mystack.push(9);
	mystack.push(10);
	mystack.push(11);
	
	printf("size=%d\n", mystack.size());
	int count = mystack.size();

	for(int i=0; i