1. 程式人生 > >實驗4:棧和佇列的基本操作實現及其應用之《進位制轉換》

實驗4:棧和佇列的基本操作實現及其應用之《進位制轉換》

#include "SeqStack.h"
template
SeqStack::SeqStack()
{
	top = -1;
}

template
void SeqStack::Push(DataType x)
{
	if (top == StackSize - 1)throw"上溢";
	top++;
	data[top] = x;
}

template
DataType SeqStack::Pop()
{
	DataType x;
	if (top == -1)throw"下溢";
	x = data[top--];
	return x;
}

template
DataType SeqStack::GetTop()
{
	if (top != -1)
	return data[top];
}

template
int SeqStack::Empty()
{
	if (top == -1) return 1;
	else return 0;
}