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_size > | arr {}
| 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

{
int8_t d{0};
if (front == -1) {
std::cout << "\nstack is empty ";
return 0;
} else if (front == rear) {
d = arr.at(front);
front = rear = -1;
} else {
d = arr.at(front++);
}
return d;
}
std::array::at
T at(T... args)
std::cout
data_structures::queue_using_array::Queue_Array::front
int8_t front
Index of head of the array.
Definition: queue_using_array.cpp:49
data_structures::queue_using_array::Queue_Array::rear
int8_t rear
Index of tail of the array.
Definition: queue_using_array.cpp:50
data_structures::queue_using_array::Queue_Array::arr
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.

{
if (front == -1) {
std::cout << "\nStack is empty";
} else {
for (int16_t i{front}; i <= rear; ++i) std::cout << arr.at(i) << " ";
}
}
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

  ele | to be added to the end of the queue

{
if (rear == arr.size() - 1) {
std::cout << "\nStack is full";
} else if (front == -1 && rear == -1) {
front = 0;
rear = 0;
arr[rear] = ele;
} else if (rear < arr.size()) {
++rear;
arr[rear] = ele;
}
}
std::array::size
T size(T... args)
Here is the call graph for this function:

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

- data_structures/queue_using_array.cpp