Algorithms_in_C++ 1.0.0
Set of algorithms implemented in C++.
data_structures::queue_using_array::Queue_Array Class Reference

Queue_Array class containing the main data and also index of head and tail of the array. More...

Collaboration diagram for data_structures::queue_using_array::Queue_Array:
[legend]

Public Member Functions

void enqueue (const int16_t &)
 Add element to the first of the queue. More...
 
int dequeue ()
 Delete element from back of the queue. More...
 
void display () const
 Show all saved data. More...
 

Private Attributes

int8_t front {-1}
 Index of head of the array.
 
int8_t rear {-1}
 Index of tail of the array.
 
std::array< int16_t, max_sizearr {}
 All stored data.
 

Detailed Description

Queue_Array class containing the main data and also index of head and tail of the array.

Member Function Documentation

◆ dequeue()

int data_structures::queue_using_array::Queue_Array::dequeue ( )

Delete element from back of the queue.

Remove element that is located at the first of the queue.

Returns
data that is deleted if queue is not empty
75 {
76 int8_t d{0};
77 if (front == -1) {
78 std::cout << "\nstack is empty ";
79 return 0;
80 } else if (front == rear) {
81 d = arr.at(front);
82 front = rear = -1;
83 } else {
84 d = arr.at(front++);
85 }
86
87 return d;
88}
T at(T... args)
int8_t front
Index of head of the array.
Definition: queue_using_array.cpp:49
int8_t rear
Index of tail of the array.
Definition: queue_using_array.cpp:50
std::array< int16_t, max_size > arr
All stored data.
Definition: queue_using_array.cpp:51
Here is the call graph for this function:

◆ display()

void data_structures::queue_using_array::Queue_Array::display ( ) const

Show all saved data.

Utility function to show all elements in the queue.

93 {
94 if (front == -1) {
95 std::cout << "\nStack is empty";
96 } else {
97 for (int16_t i{front}; i <= rear; ++i) std::cout << arr.at(i) << " ";
98 }
99}
Here is the call graph for this function:

◆ enqueue()

void data_structures::queue_using_array::Queue_Array::enqueue ( const int16_t &  ele)

Add element to the first of the queue.

Adds new element to the end of the queue.

Parameters
eleto be added to the end of the queue
58 {
59 if (rear == arr.size() - 1) {
60 std::cout << "\nStack is full";
61 } else if (front == -1 && rear == -1) {
62 front = 0;
63 rear = 0;
64 arr[rear] = ele;
65 } else if (rear < arr.size()) {
66 ++rear;
67 arr[rear] = ele;
68 }
69}
T size(T... args)
Here is the call graph for this function:

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