Hi, below I have some code segments from my program in which I need to implement a generic template class(myqueue). The elements of the queue
must be instantiated to any data type including strings. I got all that down the only problem I have is with the strings. To be able to instantiate a string data type like I did with int and double(see below) I need to write a string class but if I do that how am I supposed to instantiate a string data type from my myqueue class in order to use myqueue and node class. I really need some help.
Thank you
//genqueue.h file////
#include <iostream.h>
#include <stdlib.h>
#include <string.h>
#include <windows.h>
template<class DataT>
class myqueue;
///////////////////////
//template class node//
///////////////////////
template<class DataT>
class node
{
private:
DataT data;
node<DataT> * next;
public:
node(DataT d, node<DataT>* n=NULL):data(d), next
{}
friend class myqueue<DataT>;
};
//////////////////////////
//template class myqueue//
//////////////////////////
template<class DataT>
class myqueue
{
private:
node<DataT> * head;
node<DataT> * tail;
public:
myqueue():head(NULL), tail(NULL){} //constructor
bool empty(){return !head}
void add(DataT v);
DataT remove();
void display(); //print queue contents
};
//member functions
//main
void main()
{
int nint;
myqueue <int> qint; //for int gueue
myqueue <double> qdouble; //double gueue
// can I do this if I write a string class to get a list of queues
myqueue <string> qstring; //for string queue
**
** code here
//to add to int queue
cout<<" \t Add to int queue: "; cin>>nint; qint.add(nint);
//I should be able to add to string queue like I did to int, right-
thank you again.....
must be instantiated to any data type including strings. I got all that down the only problem I have is with the strings. To be able to instantiate a string data type like I did with int and double(see below) I need to write a string class but if I do that how am I supposed to instantiate a string data type from my myqueue class in order to use myqueue and node class. I really need some help.
Thank you
//genqueue.h file////
#include <iostream.h>
#include <stdlib.h>
#include <string.h>
#include <windows.h>
template<class DataT>
class myqueue;
///////////////////////
//template class node//
///////////////////////
template<class DataT>
class node
{
private:
DataT data;
node<DataT> * next;
public:
node(DataT d, node<DataT>* n=NULL):data(d), next
friend class myqueue<DataT>;
};
//////////////////////////
//template class myqueue//
//////////////////////////
template<class DataT>
class myqueue
{
private:
node<DataT> * head;
node<DataT> * tail;
public:
myqueue():head(NULL), tail(NULL){} //constructor
bool empty(){return !head}
void add(DataT v);
DataT remove();
void display(); //print queue contents
};
//member functions
//main
void main()
{
int nint;
myqueue <int> qint; //for int gueue
myqueue <double> qdouble; //double gueue
// can I do this if I write a string class to get a list of queues
myqueue <string> qstring; //for string queue
**
** code here
//to add to int queue
cout<<" \t Add to int queue: "; cin>>nint; qint.add(nint);
//I should be able to add to string queue like I did to int, right-
thank you again.....