Circular queue

Does anyone know how to implement a circular queue?

Answers

  • By queue I assume you are interested in a FIFO (First In First Out) data structure.

    There are many people on this forum, including myself, that could implement a circular FIFO queue. Perhaps you might gives us more information about what is to be stored in the queue and what it ios being used for.

  • no, he means a circular buffer.

    but he doesn't actually need a circular buffer. there's another thread, the https://forum.processing.org/two/discussion/23895/muffet-from-undertale thread, with the details.

  • If you google java circular buffer, you will get some good hits. Since Processing is Java, you can use them directly in your application.

    Kf

  • And koogs, pls, u are not gonna tell me what do i need. I need a circular queue or buffer to store objects. My own class

  • Okay. So you want to store some objects in a structure. Why use a circular queue? There are many other types of structures - built in ones, even - that will work for that. Like an ArrayList, say.

  • if u see the video on the link koogs posted, u will see why

  • I have seen the video. I see a need for a structure, such as an ArrayList. I do NOT see a specific need for a circular array or circular buffer at all!

  • cuz there are not infinity elements. There are, lets say 10, and when 1 is created and it moves 100 pixels (example), the second one is created also, and so on. And when the first reaches and edge, it is added to the queue, until he i needed to spawn again

  • edited August 2017

    what everybody here is trying to point out is that you can create all the elements at the start. some of them are offscreen and will become visible as they move. the ones that are onscreen will move offscreen. there's no need to keep destroying and creating things with complicated timing.

    and no need for anything more complicated than an array.

  • thats what i do, but the thing is that when an already object reaches an edge, i should move to the opposite edge and hide it too, and idk how

  • the thing is i have to hide them until the previous one moved 100 pixels, and when somene reaches an edge, wait him too until the most recent object created has moved 100 pixels too

  • You still are talking about the spider video....

    Oh Boy, you are hard to talk to

    I explained it all in the spider discussion with the video but you don't believe me

    Instead you opened two new discussions with people telling you the same as I did and you don't believe them either

  • edited August 2017

    Let's say you have a spider right from the screen (it is located far outside the screen to the right and flies left)

    x=random(width+199,width+888);

    The xSpeed is-1;

    Now it flies left

    y is some random value by the way

    When x < 0 - 100 say x = random (....... like above

    Same goes for spiders coming from the left, flying right, but other way round

  • yes, and when that spider reached the edge? and i dont want random distances on X. I want all spiders flying with the same distance between them

  • What happens when a car goes past? It doesn't stop, it doesn't cease to exist, it doesn't spawn another car...

  • no, when a car reaches left edge, it should spawn on the right edge, but when the closest car to the right edge moved also x pixels

  • Instead of random you can just say

    x=width - i*100 to distribute them evenly

    (when i is your for-loop variable for init the spiders)

    You have to distinguish between a spider flying left (xspeed<1) and right (xspeed>1)

    For the first type (going left) if (xspeed<1 && x < -120) {......

    For the second type if (xspeed<1 && x > width + 120) {......

    In both cases you reset the x to -200 or to width +200

  • That doesnt do what i want. I want them to spawn on same X with a delay between them. I have already explained this many times, stop telling me different things to do please

  • Spawn on same X ? You mean the same distance between them?

  • yesssss!!!!!!!! look, this is the best i can draw xD

    https://gyazo.com/0d1818d1ad10c46329af7fbe2a279dff

Sign In or Register to comment.