Bounded Stacks and QueuesThe data type b_stack (b_queue) is a stack (queue) with bounded maximal size. The only element that can be accessed is the last (first) element added.ExampleThe following program shows how to use a Bounded Queue. It generates ab_queue
BQ of int with at most 100 elements and appends the numbers 1 to
100 to BQ. Then it pops all elements from the queue and outputs
them.
#include <LEDA/core/b_queue.h>
int main()
{
leda::b_queue<int> BQ(100);
int i;
for (i=1; i<=100; i++) BQ.append(i);
while (!BQ.empty()) {
i=BQ.pop();
std::cout << i << " ";
}
std::cout << std::endl;
return 0;
}
Strengths
Disadvantages
TipsUse Bounded Stacks and Queues whenever it is appropriate. If you do not know the maximal size beforehand, us a Stack/Queue. |
See also:Manual Entries: |