# Algorithms_in_C++: data_structures::stack_using_queue::Stack Struct Reference

Loading...
Searching...
No Matches
data_structures::stack_using_queue::Stack Struct Reference

Stack Class implementation for basic methods of Stack Data Structure. More...

Collaboration diagram for data_structures::stack_using_queue::Stack:
[legend]

## Public Member Functions

int | top ()
void | push (int val)
| Inserts an element to the top of the stack. More...
void | pop ()
| Removes the topmost element from the stack. More...
int | size ()
| Utility function to return the current size of the stack. More...

## Public Attributes

std::queue< int64_t > | main_q
| stores the current state of the stack
std::queue< int64_t > | auxiliary_q
uint32_t | current_size = 0
| stores the current size of the stack

## Detailed Description

Stack Class implementation for basic methods of Stack Data Structure.

## Member Function Documentation

## pop()

void data_structures::stack_using_queue::Stack::pop | ( |  | ) |

inline

Removes the topmost element from the stack.

Returns
  void

{
if (main_q.empty()) {
return;
}
main_q.pop();
current_size--;
}
std::queue::empty
T empty(T... args)
std::queue::pop
T pop(T... args)
data_structures::stack_using_queue::Stack::main_q
std::queue< int64_t > main_q
stores the current state of the stack
Definition: stack_using_queue.cpp:31
data_structures::stack_using_queue::Stack::current_size
uint32_t current_size
stores the current size of the stack
Definition: stack_using_queue.cpp:34
Here is the call graph for this function:

## push()

void data_structures::stack_using_queue::Stack::push | ( | int | val | ) |

inline

Inserts an element to the top of the stack.

Parameters

  val | the element that will be inserted into the stack

Returns
  void

{
auxiliary_q.push(val);
while (!main_q.empty()) {
auxiliary_q.push(main_q.front());
main_q.pop();
}
swap(main_q, auxiliary_q);
current_size++;
}
std::queue::front
T front(T... args)
std::queue::push
T push(T... args)
data_structures::stack_using_queue::Stack::auxiliary_q
std::queue< int64_t > auxiliary_q
Definition: stack_using_queue.cpp:32
std::swap
T swap(T... args)
Here is the call graph for this function:

## size()

int data_structures::stack_using_queue::Stack::size | ( |  | ) |

inline

Utility function to return the current size of the stack.

Returns
  current size of stack

{ return current_size; }

## top()

int data_structures::stack_using_queue::Stack::top | ( |  | ) |

inline

Returns the top most element of the stack

Returns
  top element of the queue

{ return main_q.front(); }
Here is the call graph for this function:

## Member Data Documentation

## auxiliary_q

std::queue<int64_t> data_structures::stack_using_queue::Stack::auxiliary_q

used to carry out intermediate operations to implement stack

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

- data_structures/stack_using_queue.cpp