Notices
Results 1 to 3 of 3

Thread: Help with circular queues

  1. #1 Help with circular queues 
    New Member
    Join Date
    May 2011
    Posts
    3
    Hello, I am taking a java computer science course for High School, and I'm a bit confused on circular queues.

    We were learning about queues and how they worked, which I believe I have a firm understanding of, but then we ran out of time and my teacher rushed through the circular queues, and I'm a bit cloudy on them.
    I know there's something with the modulus and something about having to stop the tail from going into negative indexes in the array...

    Can anyone explain what the modulus part is? =\

    Thank you for any help,

    Bananas


    Reply With Quote  
     

  2.  
     

  3. #2  
    Forum Radioactive Isotope MagiMaster's Avatar
    Join Date
    Jul 2006
    Posts
    3,440
    The mod or modulus operator gives the remainder after an integer division. In C/C++/Java it's written as %

    So,
    5 % 3 == 2 (1 + 2/3)
    11 % 4 == 3 (2 + 3/4)

    Unfortunately, things are a little less straightforward when dealing with negative numbers (in some languages anyway).

    -7 % 4 == -3 (-1 - 3/4)

    Most people would expect this to give 1 (-2 + 1/4), which is what you'd want for looping around in an array.


    Reply With Quote  
     

  4. #3  
    New Member
    Join Date
    May 2011
    Posts
    3
    Thank you for the help
    Reply With Quote  
     

Bookmarks
Bookmarks
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •