Algorithms_in_C++ 1.0.0
Set of algorithms implemented in C++.
Loading...
Searching...
No Matches
queue_using_array.cpp File Reference

Implementation of Linear [Queue using array] (https://www.geeksforgeeks.org/array-implementation-of-queue-simple/). More...

#include <array>
#include <iostream>
Include dependency graph for queue_using_array.cpp:

Classes

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

Namespaces

namespace  data_structures
 for IO operations
 
namespace  queue_using_array
 Functions for [Queue using Array] (https://www.geeksforgeeks.org/array-implementation-of-queue-simple/) implementation.
 

Functions

int main ()
 Main function.
 

Variables

constexpr uint16_t max_size {10}
 for io operations
 

Detailed Description

Implementation of Linear [Queue using array] (https://www.geeksforgeeks.org/array-implementation-of-queue-simple/).

The Linear Queue is a data structure used for holding a sequence of values, which can be added to the end line (enqueue), removed from head of line (dequeue) and displayed.

Algorithm

Values can be added by increasing the rear variable by 1 (which points to the end of the array), then assigning new value to rear's element of the array.

Values can be removed by increasing the front variable by 1 (which points to the first of the array), so it cannot reached any more.

Author
Pooja
Farbod Ahmadian

Function Documentation

◆ main()

int main ( void )

Main function.

Allows the user to add and delete values from the queue. Also allows user to display values in the queue.

Returns
0 on exit
111 {
112 int op{0}, data{0};
114
115 std::cout << "\n1. enqueue(Insertion) ";
116 std::cout << "\n2. dequeue(Deletion)";
117 std::cout << "\n3. Display";
118 std::cout << "\n4. Exit";
119 while (true) {
120 std::cout << "\nEnter your choice ";
121 std::cin >> op;
122 if (op == 1) {
123 std::cout << "Enter data ";
124 std::cin >> data;
125 ob.enqueue(data);
126 } else if (op == 2) {
127 data = ob.dequeue();
128 std::cout << "\ndequeue element is:\t" << data;
129 } else if (op == 3) {
130 ob.display();
131 } else if (op == 4) {
132 exit(0);
133 } else {
134 std::cout << "\nWrong choice ";
135 }
136 }
137
138 return 0;
139}
Queue_Array class containing the main data and also index of head and tail of the array.
Definition queue_using_array.cpp:43
int dequeue()
Delete element from back of the queue.
Definition queue_using_array.cpp:75
void enqueue(const int16_t &)
Add element to the first of the queue.
Definition queue_using_array.cpp:58
void display() const
Show all saved data.
Definition queue_using_array.cpp:93
T exit(T... args)
int data[MAX]
test data
Definition hash_search.cpp:24
Here is the call graph for this function:

Variable Documentation

◆ max_size

constexpr uint16_t max_size {10}
constexpr

for io operations

for std::array Maximum size of the queue

23{10}; ///< Maximum size of the queue