Algorithms_in_C++ 1.0.0
Set of algorithms implemented in C++.
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.
 
void pop ()
 Removes the topmost element from the stack.
 
int size ()
 Utility function to return the current size of the stack.
 

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
61 {
62 if (main_q.empty()) {
63 return;
64 }
65 main_q.pop();
67 }
T empty(T... args)
T pop(T... args)
std::queue< int64_t > main_q
stores the current state of the stack
Definition stack_using_queue.cpp:31
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
valthe element that will be inserted into the stack
Returns
void
47 {
48 auxiliary_q.push(val);
49 while (!main_q.empty()) {
51 main_q.pop();
52 }
55 }
T front(T... args)
T push(T... args)
std::queue< int64_t > auxiliary_q
Definition stack_using_queue.cpp:32
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
73{ 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
40{ 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: