tags:

views:

100

answers:

5
+2  Q: 

stack vs queuing ?

hello im still a student and im a bit confused about stacking and queuing ? first question is,

  1. what is the main diffrence between them two ?

  2. btw there is circular queuing beside normal queuing how about that ? how do they work ? is there any different ways to queuing?

  3. im useing php, is there a simple ( very simple or easy to read ) sample code that i can learn on ( links are okay too. )?

  4. there is pop, push and etc ( stacking and queuing ), is there anything like that in php ?

Thank you very much for looking in.

A: 

It appears you are being steered towards the difference between first-in first-out and last-in first-out queues. A stack is the former, and a circular queue is an efficient implementation of the latter.

  1. A stack is a LIFO (last in, first out) queue.

  2. You can have a circular queue - these were most common on communication interface buffers as they had limited memory with data coming in asynchronously and the data being read by the CPU at different times.

  3. You can create queues in any language if you know your language well.

  4. The php website offers a lot of documentation.

PP
+1  A: 

A stack adds and removes items from the same end.

A queue adds items to the back and removes items from the front (like a line in a bank.)

There's an article about them both that explains in detail with code samples.

A circular buffer has limited space and keeps adding items in a circular fashion overwriting the ones at the end.

JoshD
+9  A: 
VolkerK
+1 for actually mentioning the proper SPL types.
Gordon
+1 . Great!!!. lets see what others say.
Adam Ramadhan
+1  A: 

http://www.php.net/manual/en/function.array-push.php

http://php.net/manual/en/function.array-pop.php

You can look at the example code there

nullptr
wew. stupid of me mised this!
Adam Ramadhan
+3  A: 

In php you would use an array() to hold your data for both stacks and queues and use the array_* functions to manipulate them. Take a look at array functions at php.net

You have

  • array_push - put a new element at end of array
  • array_pop - remove an element from end of array
  • array_shift - remove an element from the beginning of array
  • array_unshift - put a new element onto the beginning of array.

  • For a stack you'd use array_push and array_pop

  • For a queue you'd use array_push and array_shift

A circular buffer I would implement as a standalone object.

thomasmalt