---
title: "一些常用的数据结构（三）：栈"
author: "lee_3do"
date: "2010-10-05T22:07:38Z"
tags: []
categories: ["编程语言"]
slug: "untitled"
draft: false
lastmod: "2010-10-05T22:07:38Z"
id: 777575
url: "https://lee3do.iteye.com/blog/777575"
---

继续。

三。栈

    栈无非就是个从一端操作的线性表，LIFO，后进先出而已。

    结构：

```
class Stack
{
	public:
	    Stack(int siza=10);
		~Stack(){delete[] element;}
	privte:
		int top;
		int MaxSize;
		int* element;
}
```

 入栈：

```
Stack* Stack::Push(int x)
{
	if(top==MaxSize)
		//throw
	element[++top]=x;
	return *this;
}
```

 出栈：

```
Stack* Stack::Push(int &x)
{
	x = element[top--];
	return *this;
}
```