TheAlgorithms/C++ 1.0.0
All the 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 <cstdint>
#include <iostream>
Include dependency graph for queue_using_array.cpp:

Go to the source code of this file.

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 std::array
 

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

Definition in file queue_using_array.cpp.

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

Definition at line 112 of file queue_using_array.cpp.

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

Variable Documentation

◆ max_size

uint16_t max_size {10}
constexpr

for std::array

for io operations Maximum size of the queue

Definition at line 24 of file queue_using_array.cpp.

24{10};