⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 derivedlinkedstack.h

📁 data+structures+using+c的源码
💻 H
字号:
//Header file derivedLinkedStack.h

#ifndef H_derivedLinkedStack
#define H_derivedLinkedStack

#include <iostream>
#include "linkedList.h"

using namespace std;

template<class Type>
class linkedStackType: public linkedListType<Type>
{
public:
	void initializeStack();
	bool isEmptyStack();
	bool isFullStack();
	void push(const Type& newItem);
    Type top();
	void pop();
	void destroyStack();
};

template<class Type>
void linkedStackType<Type>::initializeStack()
{
    linkedListType<Type>::initializeList();
}

template<class Type>
bool linkedStackType<Type>::isEmptyStack()
{
	return linkedListType<Type>::isEmptyList();
}

template<class Type>
bool linkedStackType<Type>::isFullStack()
{
	return false;
}

template<class Type>
void linkedStackType<Type>::destroyStack()
{
	linkedListType<Type>::destroyList();
}

template<class Type>
void linkedStackType<Type>::push(const Type& newElement)
{
	linkedListType<Type>::insertFirst(newElement);
}

template<class Type>
Type linkedStackType<Type>::top()
{
    return linkedListType<Type>::front();	
}

template<class Type>
void linkedStackType<Type>::pop()
{
    nodeType<Type> *temp;

   if(first != NULL)
   {
   	    temp = first;
		first = first->link;
		count--;
		delete temp;
		if(first == NULL)
			last = NULL;	
   }
   else
	  cerr<<"Cannot remove from an empty stack."<<endl;
}


#endif

⌨️ 快捷键说明

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