Thread: Regarding queues!!

  1. #1
    Registered User
    Join Date
    Jun 2007
    Posts
    1

    Question Regarding queues!!

    Hi all,
    This is a simple doubt regarding the circular queues in C. While doing the wrap around process there are two method to do the same.

    ie, say
    front = front + 1;
    if(front == MAX_Q_SIZE)
    front = 0;

    or,

    front = (front + 1) % MAX_Q_SIZE

    Can anyone kindly explain me the difference between the two codes. I mean which one if more efficient and why?

    Thanks in advance..

  2. #2
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    If you speak about effitiency from the code support point of view - for me it is just a question of personal preferences of the programmer that has to support this code...

    If you want to know the efitiency from the program performance point of view - you should take a profiler and see
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    In the first instance, pick the one you find easiest to code, get working, and explain to someone else if necessary.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Concatenating two static queues?
    By difficult.name in forum C Programming
    Replies: 2
    Last Post: 10-18-2004, 11:19 PM
  2. stacks and queues
    By j0hnb in forum C Programming
    Replies: 4
    Last Post: 04-16-2003, 09:44 PM
  3. help with queues
    By Unregistered in forum C Programming
    Replies: 3
    Last Post: 05-21-2002, 09:09 PM
  4. queues
    By jamesb in forum C Programming
    Replies: 1
    Last Post: 04-21-2002, 08:57 PM
  5. queues
    By Unregistered in forum C Programming
    Replies: 3
    Last Post: 10-11-2001, 05:19 PM