日常说明:首先博主也是菜鸟一枚,有错误欢迎大家指正。另外本博客所有的代码博主编写后均调试
通过。重要提醒!!!!博主使用的是VS2017,如果有低版本的小伙伴
最好新建空项目将此代码复制上去。
运行结果:
stack.h
#pragma once
/**********************************
* algorithms.h :堆栈的基本操作 *
* author : shilei *
* created : 2018.3.22 *
***********************************/
#include<iostream>
#include<cstdlib>
#include"malloc.h"
#include"corecrt_malloc.h"
#include<exception>
using namespace std;
#define STACK_INIT_SIZE 20
#define STACKINCREAMENT 10
class Stack
{
private :
int *base;
int *top;
int StackSize;//堆栈的容量
int Stack_len;//当前堆栈的数据元素个数
public :
Stack();
/*~Stack();*/
Stack(int values[], int n);
void InitStack(int values[], int n);
void Push(int e);
int Pop();
void Clear_Stack();
bool Empty();
int GetTop();
int Getlength();
friend ostream&