derivedlinkedstack.h
来自「data+structures+using+c的源码」· C头文件 代码 · 共 80 行
H
80 行
//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 + =
减小字号Ctrl + -
显示快捷键?