Algorithms_in_C++ 1.0.0
Set of 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
 

Constructor & Destructor Documentation

◆ ~Queue()

Queue::~Queue ( )
inline
16 {
17 while (front) {
18 dequeue();
19 }
20 }

Member Function Documentation

◆ createNode()

void Queue::createNode ( int val)
inlineprivate
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
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 }
Definition binary_search_tree.cpp:11

◆ enqueue()

void Queue::enqueue ( int val)
inline
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
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 }

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