Tech Unleashed

Wohoo!! We're on YouTube

Saturday, 2 December 2023

C++ : Lecture 24 : Queue - Array Implementation : Mastering Queue Made Simple !

 Mastering Queue Made Simple: Your Easy Guide to Data Structures !


Array implementation of queue code [C++] :


// Shyam Sunder Kanth
// Insta : still_23.6_8
// ?Queue array implementation

#include<iostream>

using namespace std;

class Queue{
    public:
    int *arr;
    int size;
    int front;
    int rear;

    Queue(int size){
        this->size = size;
        arr = new int[size];
        front = -1;
        rear = -1;
    }

    void enque(int data){
        if(rear == size-1){
            cout<<"Queue overflow";
            return;
        }

        if(front == -1){
            front = rear = 0;
            arr[rear] = data;
            return;
        }

        rear++;
        arr[rear] = data;
    }

    void deque(){
        if(front == -1){
            cout<<"Queue Underflow.";
            return;
        }

        if(front == rear){
            front = rear = -1;
            return;
        }

        front++;
    }

    bool isEmpty(){
        if(front == -1){
            return true;
        }
        return false;
    }

    int frontEle(){
        if(front == -1){
            cout<<"Queue is empty.";
            return -1;
        }
        return arr[front];
    }

    int lastEle(){
        if(front == -1){
            cout<<"Queue is empty.";
            return -1;
        }
        return arr[rear];
    }

    int length(){
        if(front == -1){
            cout<<"Queue is empty.";
            return -1;
        }
        int cnt = 0;
        for(int i = front;i<=rear;i++){
            cnt++;
        }
        return cnt;
    }

};



int main()
{
    Queue q(5);

    q.enque(4);
    q.enque(6);
    q.enque(9);

    q.deque();
    q.deque();

    cout<<q.isEmpty()<<endl;
    cout<<q.frontEle()<<endl;
    cout<<q.lastEle()<<endl;
    cout<<q.length()<<endl;

    return 0;
}

In this video tutorial, we will explore the implementation of the queue data structure using arrays. By carefully organizing the elements in a linear data structure, queues are designed to efficiently perform insertions and deletions. With a focus on utilizing arrays for implementing a queue, we will delve into the necessary steps and techniques involved.

Firstly, we will cover the basic concept and characteristics of a queue data structure, providing essential background knowledge. Then, we will dive into a step-by-step demonstration of array implementation, elucidating the intricacies and key points to consider during the process.

By the end of this tutorial, you will have a comprehensive understanding of how to effectively implement queues using arrays and optimize your code for efficient operations. Ideal for beginners and intermediate programmers seeking to enhance their data structure skills, this video promises to equip you with valuable insights into queue implementation.

Don't miss out on this opportunity to bolster your programming prowess and master the implementation of the queue data structure with arrays. Watch this engaging video tutorial now!

If you found this video helpful, please like, comment, and subscribe to our channel for more informative content on data structures and algorithms.

In this video we’ll walk you through:

- Concept

- Operation

- Code


All codes are available at my GitHub account, check them out here:

https://github.com/shyamkanth/Placements


Check out other videos from DS Revealed playlist: https://www.youtube.com/playlist?list=PLNXqJgOsTCZOB60T9HDhMf_o8RXbNWgqS


Check out our channel here: https://www.youtube.com/@DevelopersByte


Find us at: https://shyamkanth.github.io/


Timestamps:

0:00 Intro

0:42 Concept

6:11 Enqueue operation

12:20 Dequeue operation

16:27 Front operation

16:48 Last operation

17:40 Length operation

20:06 isEmpty operation

20:40 Code

34:45 Outro


About our channel:

Our channel is about Revealing the secrets of Data Structure. We cover lots of cool stuff such as Codes, Concepts and Implementations.

Check out our channel here: https://www.youtube.com/@DevelopersByte

Don’t forget to subscribe!


Follow me on social media:

Get updates or reach out to Get updates on our Social Media Profiles!

GitHub: https://github.com/shyamkanth/

Instagram: https://instagram.com/still_23.6_8

Instagram personal: https://instagram.com/itz_sammmii

No comments:

Post a Comment