Like Tree1Likes

Queue with a circular array... nitpick !

This is a discussion on Queue with a circular array... nitpick ! within the C++ Programming forums, part of the General Programming Boards category; Thanks. In this case the max_size would be Size-1 ; because I'm using the state where the tail is one ...

  1. #16
    Registered User manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    Kolkata@India
    Posts
    2,498
    Thanks.

    In this case the max_size would be Size-1 ; because I'm using the state where the tail is one step behind head to denote the empty convention. The other conventions I read about are much much convoluted.

    I remember reading somewhere that x.empty() should by preferred to x.size()==0 . I don't remember the reason, but if it is legitimate; is that point valid here? .. as implementing empty using size seems to negate that ..
    Manasij Mukherjee | gcc-4.8.2 @Arch Linux
    Slow and Steady wins the race... if and only if :
    1.None of the other participants are fast and steady.
    2.The fast and unsteady suddenly falls asleep while running !



  2. #17
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,636
    Quote Originally Posted by manasij7479
    In this case the max_size would be Size-1 ; because I'm using the state where the tail is one step behind head to denote the empty convention. The other conventions I read about are much much convoluted.
    Ah yes, that is actually a logic error on my part.

    Quote Originally Posted by manasij7479
    I remember reading somewhere that x.empty() should by preferred to x.size()==0 . I don't remember the reason, but if it is legitimate; is that point valid here? .. as implementing empty using size seems to negate that ..
    In cases where there is some special optimisation possible that accesses the internals to determine empty but not size, with an improvement in efficiency that is not negligible, then yes. Of course, in that case a member empty can be implemented, then the non-member empty calls that instead.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #18
    Registered User manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    Kolkata@India
    Posts
    2,498
    Quote Originally Posted by laserlight View Post
    In cases where there is some special optimisation possible that accesses the internals to determine empty but not size, with an improvement in efficiency that is not negligible, then yes. Of course, in that case a member empty can be implemented, then the non-member empty calls that instead.
    In this case, as it is an array, both size and empty ..as given in the original post relies on a call to diff().
    So, I'd guess there is nothing to be gained.

    Btw. .. When it is not negligible, is it by .. say... factors like that crawling to a position in a linked list to indexed locations in arrays ?
    Manasij Mukherjee | gcc-4.8.2 @Arch Linux
    Slow and Steady wins the race... if and only if :
    1.None of the other participants are fast and steady.
    2.The fast and unsteady suddenly falls asleep while running !



  4. #19
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,636
    Quote Originally Posted by manasij7479
    Btw. .. When it is not negligible, is it by .. say... factors like that crawling to a position in a linked list to indexed locations in arrays ?
    Yeah, having a linear time size() would be an example, though it is not applicable to the standard containers.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Please ..err..nitpick my code (implementing a stack)
    By manasij7479 in forum C++ Programming
    Replies: 6
    Last Post: 10-04-2011, 05:20 PM
  2. Circular Queue
    By Giridhar Sanjay in forum C++ Programming
    Replies: 6
    Last Post: 07-02-2011, 02:22 PM
  3. Stack and Queue "quack" circular array
    By mrsirpoopsalot in forum C++ Programming
    Replies: 15
    Last Post: 10-20-2009, 03:16 PM
  4. Circular array
    By Opel_Corsa in forum C++ Programming
    Replies: 5
    Last Post: 02-16-2006, 03:15 PM
  5. circular queue
    By strotee76 in forum C++ Programming
    Replies: 2
    Last Post: 05-24-2004, 09:55 AM

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