stack.cpp

来自「语法分析器,很好的,同学写的,认为不错 .」· C++ 代码 · 共 54 行

CPP
54
字号
#include "Stack.h"
#include "assert.h"
template<class Type>
Stack<Type>::~Stack()
{
	StackNode<Type>*p;
	while(top != NULL)
	{
		p = top;
		top = top->link;
		delete p;
	}
}
template<class Type>
void Stack<Type>::Push(const Type &item)
{
	top = new StackNode<Type>(item,top);
}
template<class Type>
Type Stack<Type>::Pop()
{
//	assert(!IsEmpty());
	Type retvalue;
	if(!IsEmpty())
	{
		StackNode<Type> *p = top;
		retvalue = p->data;
		top = top->link;
		delete p;
		return retvalue;
	}
	return NULL;
	
}
template<class Type>
Type Stack<Type>::GetTop()
{
	assert(!IsEmpty());
	return top->data;
}
template<class Type>
void Stack<Type>::PrintElem()
{
	char temp[10];
	int i = 0;
	StackNode<Type> *p = top;
	while(p != NULL)
	{
		temp[i++] = p->data;
		p = p->link;
	}
	for(int j = i-1;j >= 0;j--)
		cout << temp[j];
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?