Thread: queue

  1. #1
    Registered User
    Join Date
    Oct 2010
    Posts
    1

    queue

    so i'm really struggling with this program, i'm new to c++, i have most parts done, but can't figure out my queuetype code ... i know what needs to be done, just can't figure out the code

    Code:
    #include "QueueType.h"
    
    
    QueueType::QueueType(void)
    {
    	front = NULLNODE;
    	back = NULLNODE;
    }
    
    
    QueueType::~QueueType(void)
    {
    	MakeEmpty();
    }
    
    
    bool QueueType::IsEmpty() const
    {
    	// How can we tell if the queue is empty?
    	return false;
    }
    
    bool QueueType::IsFull() const
    {
    	try
    	{
    		NodeType *tmp = new NodeType();
    		delete tmp;
    		return false;
    	}
    	catch (std::bad_alloc ex)
    	{
    		return true;
    	}
    }
    
    void QueueType::MakeEmpty()
    {
    	while (! IsEmpty())
    		Dequeue();
    }
    
    void QueueType::Enqueue(ItemType item)
    {
    	NodeType *newNode = new NodeType();
    
    	// Store data in the node and initialize next
    
    
    	// Case 1: The queue is currently empty
    	if (IsEmpty())
    	{
    		// Point front and back to newNode
    	}
    
    	// Case 2: The queue is not currently empty
    	else
    	{
    		// Point the next of back to the new node
    		// Move the back pointer to point to the new node
    	}
    }
    
    ItemType QueueType::Dequeue()
    {
    	ItemType itemToReturn;
    
    	// Store the item to return
    	// Delete the first node in the queue
    	// If we just deleted the last node in the queue, also set back to NULLNODE
    
    	return itemToReturn;
    }
    anyone have any suggestions

  2. #2
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    You usually need to remember how man items are in the queue; thus, if the number of items in the queue is 0, then it's empty, per definition.
    I am somewhat doubtful of your IsFull function, however. Just because you don't have enough memory free doesn't mean the queue is full. The queue is full when it has reached its peak of items.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Lost on Queues - Help GREATLY appreciated.
    By TetsuoShima in forum C Programming
    Replies: 3
    Last Post: 07-13-2010, 05:35 AM
  2. Help with FIFO QUEUE
    By jackfraust in forum C++ Programming
    Replies: 23
    Last Post: 04-03-2009, 08:17 AM
  3. Fixing my program
    By Mcwaffle in forum C Programming
    Replies: 5
    Last Post: 11-05-2008, 03:55 AM
  4. help with queues
    By Unregistered in forum C Programming
    Replies: 3
    Last Post: 05-21-2002, 09:09 PM
  5. help with queues
    By Unregistered in forum C Programming
    Replies: 3
    Last Post: 05-21-2002, 11:39 AM