//Hi all,can someone help with this problem
//I am stack,need to output all functions in main,with user input for queue and stack,but first queue
//This is my .h and .cpp of queue
#include "stdafx.h"

template <class ItemType>
struct NodeType;

template <class ItemType>
class QueType
{
public:
    QueType();
    // Class constructor.
    ~QueType();
    // Class destructor.    
    void MakeEmpty();
bool IsEmpty() const;
bool IsFull() const;
void Enqueue(ItemType newItem);
void Dequeue(ItemType& item);
void PrintQue();
private:
    NodeType<ItemType>* qFront;
    NodeType<ItemType>* qRear;

};

//template <class ItemType>
//struct NodeType
//{
//    ItemType info;
//    NodeType* next;
//};

template <class ItemType>
QueType<ItemType>::QueType() 
// Class constructor.
// Post:  qFront and qRear are set to NULL.
{
    qFront = NULL;
    qRear = NULL;
}

template <class ItemType>
QueType<ItemType>::~QueType()
// Class destructor.
{
    MakeEmpty();
}

template <class ItemType>
void QueType<ItemType>::MakeEmpty()
// Post: Queue is empty; all elements have been
// deallocated.
{
    NodeType<ItemType>* tempPtr;

    while (qFront != NULL)
    {
        tempPtr = qFront;
        qFront = qFront->next;
        delete tempPtr;
    }
    qRear = NULL;
}

template <class ItemType>
bool QueType<ItemType>::IsFull() const
// Returns true if there is no room for another
// ItemType on the free store;
// false otherwise.
{
    NodeType<ItemType>* ptr;
    ptr = new NodeType<ItemType>;
    if (ptr == NULL)
        return true;
    else
    {
        delete ptr;
        return false;
    }
}

template <class ItemType>
bool QueType<ItemType>::IsEmpty() const
// Returns true if there are no elements on the queue; false otherwise.
{
    return (qFront == NULL);
}

template <class ItemType>
void QueType<ItemType>::Enqueue(ItemType newItem)
// Adds newItem to the rear of the queue.
// Pre:Queue has been initialized and is not full
// Post: newItem is at rear of queue.
{
    NodeType<ItemType>* newNode;

    newNode = new NodeType<ItemType>;
    newNode->info = newItem;
    newNode->next = NULL;
    if (qRear == NULL)
        qFront = newNode;
    else
        qRear->next = newNode;
    qRear = newNode;
}

template <class ItemType>
void QueType<ItemType>::Dequeue(ItemType& item)
// Removes front item from the queue and returns
// it in item.
// Pre:  Queue has been initialized and is not
// empty.
// Post: Front element has been removed from
// queue.
//       item is a copy of removed element.
{
    NodeType<ItemType>* tempPtr;

    tempPtr = qFront;
    item = qFront->info;
    qFront = qFront->next;
    if (qFront == NULL)
        qRear = NULL;
    delete tempPtr;
}

template <class ItemType>
void QueType<ItemType>::PrintQue()
{ 
    NodeType<ItemType>* tempPtr;
    tempPtr = qFront;
    while(tempPtr != NULL)
    {
        cout << tempPtr ->info << endl;
        tempPtr =tempPtr->next;

    }


}
///////////////  This is my main //////////////////////////
// Queues and Stacks.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include "stack.h"
#include "queue.h"

using namespace std;

int showMenu(void);
void MakeEmpty();
void Enqueue( newItem);
void Dequeue(& item)
void PrintQue();
void reverseDataInsideTheQueue();

int _tmain(int argc, _TCHAR* argv[])
{


    bool quit =false;
    int option;
    do{

        option = showMenu();
        switch ( option )
        {
        case 1:
             MakeEmpty();
            break;
        case 2:
         Enqueue( newItem);
            break;
        case 3:
            Dequeue(&item);
             break;
        case 4:
            PrintQue();
            break;
        case 5:
            reverseDataInsideTheQueue();
            break;
        case 6:
            quit = true;
            break;
        default:
            cout << "Invalid Entry, Please Try Again";

        }

    }while(!quit);




    return 0;
}

int showMenu(void)
{
    int option;
    cout << " Main Menu" << endl;
    cout << " 1.MakeEmpty" << endl;
    cout << " 2.Add data to the input end of the queue" << endl;
    cout << " 3.Remove data from the output end of the queue " << endl;
    cout << " 4.Print the contents of the queue" << endl;
    cout << " 5.Reverse the data inside the queue " << endl;
    cout << " Enter your option here: " << endl;
    cin >> option;

    return option;





};
 void MakeEmpty()
{

}



void Enqueue( newItem)
 {



 }
 void Dequeue(& item)
 {


 }
 void PrintQue()
 {




 }
 void reverseDataInsideTheQueue()
 {



 }

 ///some of the prototypes gives an error. How do i implement all 5 options from menu?

First off, your prototypes that take parameters don't have any datatypes just variable names.

Secondly, the functions you want to call, are already inside the class. You shouldn't need to declare new ones, just create an object of that class.

Edited 2 Years Ago by tinstaafl

First of all your your design or approach to your idea is wrong.
you must understand or read more about templates. Every template must be initialized with a data type.
1.Example: in the main I don't see that. Eg. Node<?> *foo. Etc.
2. Your there is no data in your
container to manipulate. You must put data first because how do you want to printque if it's empty.??

Form HTC 816.

This question has already been answered. Start a new discussion instead.