DSA - Data Structures and Algorithms
Loading...
Searching...
No Matches
stack.h File Reference

This file contains implementation of Stack class. More...

#include "list.h"
#include <initializer_list>
#include <iostream>
#include <utility>

Go to the source code of this file.

Classes

class  dsa::Stack< T >
 Implements Stack class. More...

Functions

template<typename T>
auto dsa::operator== (const Stack< T > &stack1, const Stack< T > &stack2) -> bool
 The relational operator compares two Stack objects.
template<typename T>
auto dsa::operator< (const Stack< T > &stack1, const Stack< T > &stack2) -> bool
 The relational operator compares two Stack objects.
template<typename T>
auto dsa::operator<< (std::ostream &out, const Stack< T > &stack) -> std::ostream &
 Overloads operator to print all elements of Stack.
template<typename T>
auto dsa::operator!= (const Stack< T > &stack1, const Stack< T > &stack2) -> bool
 The relational operator compares two Stack objects.
template<typename T>
auto dsa::operator> (const Stack< T > &stack1, const Stack< T > &stack2) -> bool
 The relational operator compares two Stack objects.
template<typename T>
auto dsa::operator<= (const Stack< T > &stack1, const Stack< T > &stack2) -> bool
 The relational operator compares two Stack objects.
template<typename T>
auto dsa::operator>= (const Stack< T > &stack1, const Stack< T > &stack2) -> bool
 The relational operator compares two Stack objects.

Detailed Description

This file contains implementation of Stack class.

Author
Michal Zygmunt

Definition in file stack.h.

Function Documentation

◆ operator!=()

template<typename T>
auto dsa::operator!= ( const Stack< T > & stack1,
const Stack< T > & stack2 ) -> bool

The relational operator compares two Stack objects.

Template Parameters
Ttype of data stored in Stack
Parameters
[in]stack1input container
[in]stack2input container
Return values
trueif containers are not equal
falseif containers are equal

Definition at line 330 of file stack.h.

331 {
332 return !(operator==(stack1, stack2));
333 }
constexpr auto operator==(const Array< T, N > &lhs, const Array< T, N > &rhs) noexcept(noexcept(*lhs.begin()== *rhs.begin())) -> bool
The relational operator compares two Array objects.
Definition array.h:591

◆ operator<()

template<typename T>
auto dsa::operator< ( const Stack< T > & stack1,
const Stack< T > & stack2 ) -> bool

The relational operator compares two Stack objects.

Forward friend declaration to access internal container comparison operator.

Template Parameters
Ttype of data stored in Stack
Parameters
[in]stack1input container
[in]stack2input container
Return values
trueif the content of stack1 are lexicographically less than the content of stack2
falseotherwise

Definition at line 346 of file stack.h.

347 {
348 return stack1.container < stack2.container;
349 }

◆ operator<<()

template<typename T>
auto dsa::operator<< ( std::ostream & out,
const Stack< T > & stack ) -> std::ostream&

Overloads operator to print all elements of Stack.

Template Parameters
Ttype of initializer list elements
Parameters
[in,out]outreference to output stream
[in]stackStack to print
Returns
std::ostream& reference to std::ostream

Definition at line 292 of file stack.h.

293 {
294 Stack<T> temp{ stack };
295
296 while (!temp.empty())
297 {
298 out << temp.top() << ' ';
299 temp.pop();
300 }
301
302 return out;
303 }
Implements Stack class.
Definition stack.h:44
void pop()
Function removes the top element of Stack.
Definition stack.h:269
auto top() -> reference
Function returns pointer to Stack top element.
Definition stack.h:239
auto empty() const -> bool
Function checks if container has no elements.
Definition stack.h:251

◆ operator<=()

template<typename T>
auto dsa::operator<= ( const Stack< T > & stack1,
const Stack< T > & stack2 ) -> bool

The relational operator compares two Stack objects.

Template Parameters
Ttype of data stored in Stack
Parameters
[in]stack1input container
[in]stack2input container
Return values
trueif the content of stack1 are lexicographically less or equal than the content of stack2
falseotherwise

Definition at line 378 of file stack.h.

379 {
380 return !(operator>(stack1, stack2));
381 }
auto operator>(const List< T > &list1, const List< T > &list2) -> bool
The relational operator compares two List objects.
Definition list.h:1980

◆ operator==()

template<typename T>
auto dsa::operator== ( const Stack< T > & stack1,
const Stack< T > & stack2 ) -> bool

The relational operator compares two Stack objects.

Forward friend declaration to access internal container comparison operator.

Template Parameters
Ttype of data stored in Stack
Parameters
[in]stack1input container
[in]stack2input container
Return values
trueif containers are equal
falseif containers are not equal

Definition at line 315 of file stack.h.

316 {
317 return stack1.container == stack2.container;
318 }

◆ operator>()

template<typename T>
auto dsa::operator> ( const Stack< T > & stack1,
const Stack< T > & stack2 ) -> bool

The relational operator compares two Stack objects.

Template Parameters
Ttype of data stored in Stack
Parameters
[in]stack1input container
[in]stack2input container
Return values
trueif the content of stack1 are lexicographically greater than the content of stack2
falseotherwise

Definition at line 362 of file stack.h.

363 {
364 return operator<(stack2, stack1);
365 }
auto operator<(const List< T > &list1, const List< T > &list2) -> bool
The relational operator compares two List objects.
Definition list.h:1944

◆ operator>=()

template<typename T>
auto dsa::operator>= ( const Stack< T > & stack1,
const Stack< T > & stack2 ) -> bool

The relational operator compares two Stack objects.

Template Parameters
Ttype of data stored in Stack
Parameters
[in]stack1input container
[in]stack2input container
Return values
trueif the content of s1 are lexicographically greater or equal than the content of s2
falseotherwise

Definition at line 394 of file stack.h.

395 {
396 return !(operator<(stack1, stack2));
397 }