Re: what is a stack

thufir.hawat_at_mail.com
Date: 07/16/04


Date: Thu, 15 Jul 2004 22:10:11 -0700

There's FILO and FIFO, they're both implemented as a regular old array (at
least as I learned it in FORTRAN).

////////////////////////////begin trivia///////////////////
FILO
if you enter [a,b,c,d] into a FILO array and then remove the elements,
you'll remove them as [d,c,b,a], which'd be how they were entered. this is
a stack. Consider a stack of plates in a cafeteria, plate "a" was put on
the stack first so it's on the bottom, and is the last one off.

FIFO
The reverse of a stack, aka a queue. If you enter [a,b,c,d] into a queue
you'd access them by pop(queue) which'd return an element. the element's
be returned in order of [a,b,c,d]. Think of standing in a queue at a bank
(as lotsa foreigners use the word queue (no offense to you foreigners
intended)): whoever's standing in line longest get's to the teller. The
inverse function of pop(queue) is push(element); ie push(e) would put "e"
at the end of the queue.

It get's more interesting when you use a second array to keep the place of
the nodes, which allows you to make circular lists, or even circular
linked lists.

In java, nowadays, it's all academic. The collections do all this
low-level stuff behind the scenes and use a consistent API to make it
portable.
/////////////////////////end trivia/////////////////

I think you're not really referring to stacks and queues in java per se,
but the heap and queue's in memory or something. AFAIK this is totally
opaque in java, so, in a sense, isn't "necesarry" to know. I think it's
related to garbage collection, which, in general, you're not supposed to
have to deal with. OTOH the more you know the better.

HTH,

Thufir Hawat



Relevant Pages

  • Re: Fixed-size FIFO queue
    ... But when trying to get o/p u will feel like a FIFO. ... I only want to use array not linked list. ... The question is when the queue is full, there are ten characters in the ... When the 11th character comes, ...
    (comp.lang.c)
  • Re: Depth Fist Search and Breadth First Search and using array
    ... array to act as a Stack, but we can just use recursion. ... you can certainly do breadth first search without a queue. ...
    (comp.programming)
  • Stack and Queue
    ... // Program to implement both stack and queue on an array ... int main ... My logic for stack is which ever item is stored in the last should be ... taken out first and so on...so I have filled the array and printing ...
    (comp.lang.c)
  • Re: circular buffer
    ... us to have 'rubber' queue, ... For a FIFO you don't need both. ... FIFO!= stack ... Posted via a free Usenet account from http://www.teranews.com ...
    (comp.programming)
  • Re: circular buffer
    ... us to have 'rubber' queue, ... For a FIFO you don't need both. ... Just keep a pointer to the tail. ... FIFO!= stack ...
    (comp.programming)