c语言数据结构队列主函数 数据结构队列代码c语言( 四 )


};
template class Type
const int StackType::DefaultSize = 10;
template class Type
StackType::Stack(int pMaxSize) {
MaxSize = pMaxSize;
stack = new Type[MaxSize];
top = -1;
}
template class Type
StackType::Stack(Type pArray[], int pLen, int pMaxSize) {
stack = new Type[pMaxSize];
for ( int i = 0; ipLen; i++ )
{
stack[i] = pArray[i];
}
top = pLen - 1;
MaxSize = pMaxSize;
}
template class Type
inline bool StackType::IsFull() {
if (top == MaxSize - 1) return true;
else return false;
}
template class Type
inline bool StackType::IsEmpty() {
if (top == -1) return true;
else return false;
}
template class Type
void StackType::Add(const TypepX) {
if (IsFull())
{
StackFull();
stack[++top] = pX;
}
else stack[++top] = pX;
}
template class Type
Type * StackType::Delete(TypepX) {
if (IsEmpty())
{
StackEmpty();
return 0;
}
pX = stack[top--];
return pX;
}
template class Type
void StackType::StackEmpty() {
cout"栈已空,不能进行弹出操作!"endl;
}
template class Type
void StackType::StackFull() {
Type * nStack = new Type[MaxSize * 2];
for ( int i = 0; i = top; i++ )
{
nStack[i] = stack[i];
}
MaxSize = MaxSize * 2;
delete [] stack;
stack = nStack;
cout"栈已满,栈的自动容量自动扩充为原来的两倍 ("MaxSize")"endl;
}
template class Type
ostreamoperator(ostreampOutput, const StackTypepS) {
if (pS.top == -1)
{
pOutput"空栈"endl;
return pOutput;
}
for ( int i = 0; i = pS.top; i++ )
{
pOutputpS.stack[i]" ";
}
return pOutput;
}
template class Type
void StackType::Empty() {
top = -1;
}
template class Type
int StackType::GetSize() {
return top + 1;
}
#endif
关于c语言数据结构队列主函数和数据结构队列代码c语言的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站 。

推荐阅读