#include"utility.h"
//#include"C:\Users\Andy\Documents\Visual Studio 2010\Projects\stack\stack\utility.cpp"
#include"queue.h"
#include <cctype>
void help(){
cout<<"This progrom is to test the class queue "
<<"and you can choose this any opreations supported after reading this users's guide"<<endl;
cout<<"[A]ppend is to append the element input the queue "<<" S[erve] is to remove one element"<<endl;
}
template<typename T>
int do_command(char command, Queue<T>& queue){
command=toupper(command);
switch (command){
T term;
case'A':
cout<<"please input a elment"<<endl;
cin>>term;
queue.append(term);
break;
case'S':
queue.service();
break;
case'Q':
return 0;
}
return 0;
}
char get_command(){
char c;
cout<<"please input the command "<<endl;
cin>>c;
while(1)
{
if(c=='A'||c=='a'||c=='S'||c=='s'||c=='Q'||c=='q')
; // do nothing
else
{
cout<<"wrong command ,pls read turn to help for instructions,and input again"<<endl;
cin>>c;}
return c;
}
}
int main(){
/*
*pre:user choose one opreation supported by linked queue
*post:this program do that opreation accordingly ,and quit if user don't want to test any more
*user:class linked queue ,and its methods ,created by Andy ,12/7/2010;
*
*/
help();
Queue<double> my_queue;
while(user_says_yes())
{
do_command(get_command(),my_queue);
}
}
#include"queue.h"
#include"utility.h"
//#include <new>
template<typename T>
Error_code Queue<T>:: service()
{
if(front==Null) return fail;
else{
Node * p=top;
top=top->next;
delete p;
return success;}
}
/*this method append one element into the queue,return fail if memory is not enough to New
pre:None
post:append one element into the queue if there enough memory to New ,else return Error_code
*/
template<typename T>
Error_code Queue<T>:: append(const T& entry){
Node<T> *new_rear = new Node(item);
if (new_rear == NULL) return overflow;
if (rear == NULL) front = rear = new_rear;
else {
rear->next = new_rear;
rear = new_rear;
}
return success;
}
the code it's a little big long ,I didn't post it all .