TheAlgorithms/C++ 1.0.0
All the algorithms implemented in C++
Loading...
Searching...
No Matches
Queue Class Reference
Collaboration diagram for Queue:
[legend]

Public Member Functions

void enqueue (int val)
 
void dequeue ()
 
void traverse ()
 

Public Attributes

nodet [100]
 
int front
 
int rear
 

Private Member Functions

 Queue (const Queue &)=delete
 
Queueoperator= (const Queue &)=delete
 
void createNode (int val)
 

Private Attributes

nodefront = nullptr
 
noderear = nullptr
 

Detailed Description

Definition at line 17 of file binary_search_tree.cpp.

Constructor & Destructor Documentation

◆ ~Queue()

Queue::~Queue ( )
inline

Definition at line 16 of file circular_queue_using_linked_list.cpp.

16 {
17 while (front) {
18 dequeue();
19 }
20 }

Member Function Documentation

◆ createNode()

void Queue::createNode ( int val)
inlineprivate

Definition at line 23 of file circular_queue_using_linked_list.cpp.

23 {
24 auto* nn = new node;
25 nn->data = val;
26 nn->next = nullptr;
27 front = nn;
28 rear = nn;
29 }
struct node { int data; int height; struct node *left; struct node *right;} node
for std::queue
Definition avltree.cpp:13

◆ dequeue()

void Queue::dequeue ( )
inline

Definition at line 43 of file circular_queue_using_linked_list.cpp.

43 {
44 if (front == nullptr) {
45 return;
46 }
47 const node* const n = front;
48 if (front == rear) {
49 front = nullptr;
50 rear = nullptr;
51 } else {
52 front = front->next;
53 rear->next = front;
54 }
55 delete n;
56 }

◆ enqueue()

void Queue::enqueue ( int val)
inline

Definition at line 32 of file circular_queue_using_linked_list.cpp.

32 {
33 if (front == nullptr || rear == nullptr) {
34 createNode(val);
35 } else {
36 node* nn = new node;
37 nn->data = val;
38 rear->next = nn;
39 nn->next = front;
40 rear = nn;
41 }
42 }

◆ traverse()

void Queue::traverse ( )
inline

Definition at line 57 of file circular_queue_using_linked_list.cpp.

57 {
58 if (front == nullptr) {
59 return;
60 }
61 const node* ptr = front;
62 do {
63 std::cout << ptr->data << ' ';
64 ptr = ptr->next;
65 } while (ptr != front);
66 std::cout << '\n';
67 }

Member Data Documentation

◆ front [1/2]

int Queue::front

Definition at line 19 of file binary_search_tree.cpp.

◆ front [2/2]

node* Queue::front = nullptr
private

Definition at line 8 of file circular_queue_using_linked_list.cpp.

◆ rear [1/2]

int Queue::rear

Definition at line 20 of file binary_search_tree.cpp.

◆ rear [2/2]

node* Queue::rear = nullptr
private

Definition at line 9 of file circular_queue_using_linked_list.cpp.

◆ t

node* Queue::t[100]

Definition at line 18 of file binary_search_tree.cpp.


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