I need help writing code for my print function in a linked queue adt

queue.h

template <class ItemType>       // record type for nodes on queue
struct NodeType
{
    ItemType info;
    NodeType* next;
};

template <class ItemType>
class QueueType
{
    public:

        QueueType();
        QueueType(const QueueType &);  // Copy constructor
        ~QueueType();                // Class destructor.

        void MakeEmpty();              // Initializes the queue to an empty state
        bool IsEmpty() const;            // Determines whether the queue is empty.
        bool IsFull() const;               // Determines whether the queue is full.

        void Enqueue(ItemType newItem);    // Adds newItem to the rear of the queue.
        void Dequeue(ItemType & item);     // Removes front item from the queue and
        // returns it in the parameter.

        ostream & Print(ostream &);            // Prints contents of queue to screen
        QueueType& operator= (const QueueType &);     // Function: operator=

    private:
        NodeType<ItemType>* front;      // pointer to front node
        NodeType<ItemType>* rear;       // pointer to rear node
};

Print function in queue.h

//-----------------------------------------------------------------
// Function: Print - // Prints Results of queue
// Pre:
// Post: Cout << statetment of queue contants
template <class ItemType>
ostream & QueueType<ItemType>::Print(ostream & stream)
{
        NodeType<ItemType>* tempPtr;
        int counter = tempPtr;

        stream << "The queue contains: " << endl;

        while (counter != 0)
        {
                stream << rear[counter] << " ";
                counter--;
        }
        return stream;
}

queueTest.cpp - This is how im trying to implement it

else if (num == 6)
                {
                        queue.Print(QueueType<ItemType>ostream & stream);
                        cout << endl;
                }

stream << rear[counter] << " ";

um... how the hell do you expect this to work?

this is a linked list, not an array; you cannot index it like that; you have to traverse the links

um... how the hell do you expect this to work?

this is a linked list, not an array; you cannot index it like that; you have to traverse the links

Well, I'm not worried about the implementation file right now, I'm more worried about getting it to work in the client code... I just put something there as a filler sort of speak

Which of all those files contains the problem you are trying to resolve? queueTest.cpp ? In that file line 3 is just wrong

ostream out("outfile.txt");
<snip>
 queue.Print(out);
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.