Algorithmic Solutions > LEDA > LEDA Guide > Simple, Basic, and Advanced Data Types > Basic Data Types > Bounded Stacks and Queues

## Bounded Stacks and Queues

The 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.

### Example

The following program shows how to use a Bounded Queue. It generates a ```b_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

• very simple data type
• very fast (even faster than Stacks and Queues)
• space efficient

• set of operations is very restricted (no access to elements other than last (first) added, no searching, no iterating)
• maximal size is bounded

### Tips

Use Bounded Stacks and Queues whenever it is appropriate. If you do not know the maximal size beforehand, us a Stack/Queue.

Stacks and Queues

Manual Entries:

Bounded Stacks

Bounded Queues