queue

This is a discussion on queue within the C++ Programming forums, part of the General Programming Boards category; how do i know whether the circular queue is full or empty?...

  1. #1
    Registered User
    Join Date
    Sep 2002
    Posts
    3

    queue

    how do i know whether the circular queue is full or empty?

  2. #2
    Registered User
    Join Date
    Nov 2001
    Posts
    1,348
    One solution is a counter.

    Kuphryn

  3. #3
    Registered User
    Join Date
    Sep 2002
    Posts
    3
    what is a counter

  4. #4
    Registered User
    Join Date
    Sep 2002
    Posts
    3
    any other solutions

  5. #5
    Registered User
    Join Date
    Oct 2001
    Posts
    12
    1) Counter solution

    The best one. All you need is an integer variable. Whenever you add an item to your queue, you need to increment it by one and vice versa: whenever you remove an item, you need to decrement the counter by one. Counter is initalized with 0, of course.

    2) Solution w/o counter

    You can calculate the number of items in your queue from the indexes of tail & head. It's a little tricky since tail can be < than head (the values of head and tail when the queue is empty should be taken into consideration too).

    Conclusion:

    Use solution #1

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help with FIFO QUEUE
    By jackfraust in forum C++ Programming
    Replies: 23
    Last Post: 04-03-2009, 08:17 AM
  2. Fixing my program
    By Mcwaffle in forum C Programming
    Replies: 5
    Last Post: 11-05-2008, 02:55 AM
  3. help with queues
    By Unregistered in forum C Programming
    Replies: 3
    Last Post: 05-21-2002, 09:09 PM
  4. help with queues
    By Unregistered in forum C Programming
    Replies: 3
    Last Post: 05-21-2002, 11:39 AM
  5. queue help
    By Unregistered in forum C Programming
    Replies: 2
    Last Post: 10-29-2001, 08:38 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21