itpp::Stack< T > Class Template Reference

General stack class. More...

`#include <itpp/base/stack.h>`

## Public Member Functions

| Stack ()
| Default constructor.
| Stack (int n)
| Create a Stack of size `n`.
| Stack (const Stack< T > &s)
| Create a copy of `s`.
virtual | ~Stack ()
| Default destructor.
T | pop ()
| Pop the topmost element of the stack.
T | peek () const
| Peek at the topmost element of the stack, without removing it.
void | push (T v)
| Push an element at top of stack.
void | clear ()
| Empty the stack.
void | operator= (const Stack< T > &s)
| Assignment operator.
int | size () const
| Returns the maximum number of data elements the stack can store.
int | no_elements () const
| Returns the number of data elements currently in the stack.
void | set_size (int n, bool copy=false)
| Resizing a Stack<T>.

## Detailed Description

template<class T>
class itpp::Stack< T >

General stack class.

This class is a general stack class for arbitrary types.

For rarely used types you will need to instantiate the class by

template class Stack<type>;
itpp::Stack::Stack
Stack()
Default constructor.
Definition stack.h:110

The following example shows how to define a Stack of vectors:

vec a = randn(10);
vec b = randn(20);
Stack<vec> my_stack(10);
my_stack.push(a);
my_stack.push(b);
cout << my_stack.pop() << " " << my_stack.pop() << endl ;
itpp::randn
double randn(void)
Generates a random Gaussian (0,1) variable.
Definition random.h:831

Definition at line 66 of file stack.h.

## Constructor & Destructor Documentation

## Stack() [1/3]

template<class T>

itpp::Stack< T >::Stack | ( |  | ) |

Default constructor.

Definition at line 110 of file stack.h.

Referenced by operator=(), and Stack().

## Stack() [2/3]

template<class T>

itpp::Stack< T >::Stack | ( | int | n | ) |

Create a Stack of size `n`.

Definition at line 118 of file stack.h.

## Stack() [3/3]

template<class T>

itpp::Stack< T >::Stack | ( | const Stack< T > & | s | ) |

Create a copy of `s`.

Definition at line 125 of file stack.h.

References Stack().

## ~Stack()

template<class T>

itpp::Stack< T >::~Stack | ( |  | ) |

virtual

Default destructor.

Definition at line 136 of file stack.h.

## Member Function Documentation

## pop()

template<class T>

T itpp::Stack< T >::pop | ( |  | ) |

Pop the topmost element of the stack.

Definition at line 142 of file stack.h.

References it_error_if.

## peek()

template<class T>

T itpp::Stack< T >::peek | ( |  | ) | const

Peek at the topmost element of the stack, without removing it.

Definition at line 150 of file stack.h.

References it_error_if.

## push()

template<class T>

void itpp::Stack< T >::push | ( | T | v | ) |

Push an element at top of stack.

Definition at line 157 of file stack.h.

References it_error_if.

## clear()

template<class T>

void itpp::Stack< T >::clear | ( |  | ) |

Empty the stack.

Definition at line 165 of file stack.h.

## operator=()

template<class T>

void itpp::Stack< T >::operator= | ( | const Stack< T > & | s | ) |

Assignment operator.

Definition at line 195 of file stack.h.

References set_size(), and Stack().

## size()

template<class T>

int itpp::Stack< T >::size | ( |  | ) | const

inline

Returns the maximum number of data elements the stack can store.

Definition at line 91 of file stack.h.

## no_elements()

template<class T>

int itpp::Stack< T >::no_elements | ( |  | ) | const

inline

Returns the number of data elements currently in the stack.

Definition at line 93 of file stack.h.

## set_size()

template<class T>

void itpp::Stack< T >::set_size | ( | int | n,
|  | bool | copy = false )

Resizing a Stack<T>.

Definition at line 204 of file stack.h.

References itpp::min().

Referenced by operator=().

The documentation for this class was generated from the following file:

- itpp/base/stack.h

Generated on for IT++ by Doxygen 1.15.0