- FIFO using LIFO
- Posted by karthikbg on November 14th, 2006
Hi,
Any Ideas for Implementing a FIFO using LIFO ?
Thx in advans
Karthik Balaguru
- Posted by Richard Heathfield on November 14th, 2006
karthikbg said:
Use two LIFOs.
--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: normal service will be restored as soon as possible. Please do not
adjust your email clients.
- Posted by Logan Shaw on November 14th, 2006
Richard Heathfield wrote:
If you're going to use more than one, it would be
more efficient to use N of them (and only ever
store one item in each). :-)
- Logan
- Posted by Rahul on November 21st, 2006
I think I am late but you can use only one single LIFO with two top
pointers top1 and top 2 pointing at stack[0].One assume that array is
full other assume that array is empty. When any element gets added top1
is incremented and when element is deleted top2 is incremented.
- Posted by Pascal Bourguignon on November 21st, 2006
"Rahul" <rahuls@huawei.com> writes:
Then you aren't using a LIFO, you're using a normal vector.
Who said there was such a thing as stack[0] ?
A LIFO is usually implemented with a single-linked list.
--
__Pascal Bourguignon__ http://www.informatimago.com/
ADVISORY: There is an extremely small but nonzero chance that,
through a process known as "tunneling," this product may
spontaneously disappear from its present location and reappear at
any random place in the universe, including your neighbor's
domicile. The manufacturer will not be responsible for any damages
or inconveniences that may result.
- Posted by Robert Maas, see http://tinyurl.com/uh3t on November 21st, 2006
Keep two LIFOs. Push all new items into the first LIFO.
Pop as needed from the second LIFO, but whenever that second LIFO
goes empty you quickly pop everything from the first LIFO and push
into second LIFO.
Most of the time the pushing and popping can run asynchronously,
but whenever you need to do that pop-push loop you have to lock the
push-to-first-LIFO process so no new items get pushed until the
pop-push loop is done. If you need asynchronous behaviour available
*all* the time, then when the second LIFO runs empty you quickly
move the first LIFO to a temporary place and put a new empty LIFO
in its place ready to immediately get new items.