基本功能函数 BaseFun.h

王朝other·作者佚名  2006-01-09
窄屏简体版  字體: |||超大  

///////////////////////////

// //

// 基本功能函数 BaseFun.h //

// //

//////////////////////////

void GRAPH();

void LIST();

void STACK();

void QUEUE();

void COMPOSITOR();

void BINTREE();

///////////////////////////

// //

// 堆栈功能函数 Stack.cpp/ /

// //

//////////////////////////

#include"Stack.h"

#include"iostream.h"

const int INT =13;

const double FLOAT= 13.33;

const char CHAR ='a';

template<class Type>

void Stack_Push(Stack<Type> &StackOPP)

{

cout<<"请输入要插入的数据项: ";

Type item;

cin>>item;

StackOPP.Push(item);

}

template<class Type>

void Stack_Pop(Stack<Type> &StackOPP)

{

if(!StackOPP.ISEmpty())

{

cout<<"出栈数据项: ";

cout<<StackOPP.Pop()<<endl;

}

else

{

cout<<"堆栈已经为空!"<<endl;

}

}

template<class Type>

void Stack_ISEmpty(Stack<Type> &StackOPP)

{

if(!StackOPP.ISEmpty())

cout<<"堆栈不空,还有"<<StackOPP.GetNum()<<"数据项!"<<endl;

else

cout<<"堆栈为空!"<<endl;

}

template<class Type>

void Stack_GetTop(Stack<Type> &StackOPP)

{

if(!StackOPP.ISEmpty())

cout<<"栈顶元素为:"<<StackOPP.GetTop()<<endl;

else

cout<<"堆栈为空!"<<endl;

}

template<class Type>

void Stack_MakeEmpty(Stack<Type> &StackOPP)

{

if(!StackOPP.ISEmpty())

{

StackOPP.MakeEmpty();

cout<<"堆栈已经销毁!"<<endl;

}

else

{

cout<<"销毁失败!"<<endl;

}

}

template<class Type>

void StackINI(Type temp)

{

Stack<Type> StackOPP;

do

{

cout<<"堆栈的操作: "<<endl

<<" 1) 插入堆栈"<<endl

<<" 2) 出栈"<<endl

<<" 3) 堆栈是否为空"<<endl

<<" 4) 得栈顶数据项"<<endl

<<" 5) 销毁堆栈"<<endl

<<" X) 退出堆栈操作"<<endl;

int item;

cin>>item;

switch(item)

{

case 1: Stack_Push(StackOPP); break;

case 2: Stack_Pop(StackOPP); break;

case 3: Stack_ISEmpty(StackOPP); break;

case 4: Stack_GetTop(StackOPP); break;

case 5: Stack_MakeEmpty(StackOPP); break;

default: return ;

}

}while(true);

}

void STACK()

{

int item;

cout<<"清选择数据类型: 1) 整型 2) 浮点型 3) 字符型 X) 退出: ";

cin>>item;

switch(item)

{

case 1: StackINI(INT); break; //根据不同的用户需要选择数据类型

case 2: StackINI(FLOAT); break;

case 3: StackINI(CHAR); break;

default: return ; break;

}

}

///////////////////////////

// //

// 队列功能函数 Queue.h //

// //

//////////////////////////

#include"Queue.h"

const int INT =13;

const double FLOAT= 13.33;

const char CHAR ='a';

template<class Type>

void Queue_Enter(Queue<Type> &QueueOPP)

{

cout<<"请输入要插入队列的数据: ";

Type item;

cin>>item;

QueueOPP.EnQueue(item);

}

template<class Type>

void Queue_Del(Queue<Type> &QueueOPP)

{

if(!QueueOPP.ISEmpty())

{

cout<<"出队数据:"<<QueueOPP.DelQueue()<<endl;

}

else

{

cout<<"队列已为空!"<<endl;

}

}

template<class Type>

void Queue_ISEmpty(Queue<Type> &QueueOPP)

{

if(QueueOPP.ISEmpty())

{

cout<<"队列已空!"<<endl;

}

else

{

cout<<"队列不空!"<<endl;

}

}

template<class Type>

void Queue_GetFront(Queue<Type> &QueueOPP)

{

if(!QueueOPP.ISEmpty())

{

cout<<"队头元素为: "<<QueueOPP.GetFront()<<endl;

}

else

{

cout<<"队列已空!"<<endl;

}

}

template<class Type>

void Queue_MakeEmpty(Queue<Type> &QueueOPP)

{

QueueOPP.MakeEmpty();

cout<<"队列清空!"<<endl;

}

template<class Type>

void QueueINI(Type temp)

{

Queue<Type> QueueOPP;

do

{

cout<<"队列的操作: "<<endl

<<" 1) 插入队列"<<endl

<<" 2) 出队"<<endl

<<" 3) 队列是否为空"<<endl

<<" 4) 得队头数据项"<<endl

<<" 5) 销毁队列"<<endl

<<" X) 退出队列操作"<<endl;

int item;

cin>>item;

switch(item)

{

case 1: Queue_Enter(QueueOPP); break;

case 2: Queue_Del(QueueOPP); break;

case 3: Queue_ISEmpty(QueueOPP); break;

case 4: Queue_GetFront(QueueOPP); break;

case 5: Queue_MakeEmpty(QueueOPP); break;

default: return ;

}

}while(true);

}

void QUEUE() //根据不同的用户需要选择数据类型

{

int item;

cout<<"清选择数据类型: 1) 整型 2) 浮点型 3) 字符型 X) 退出: ";

cin>>item;

switch(item)

{

case 1: QueueINI(INT); break;

case 2: QueueINI(FLOAT); break;

case 3: QueueINI(CHAR); break;

default: return ; break;

}

}

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有 導航