Giter Site home page Giter Site logo

Comments (3)

jinyingtan avatar jinyingtan commented on August 28, 2024

Is this still open?

from data-structures-algorithms.

smoholkar avatar smoholkar commented on August 28, 2024

is this open still? If yes, does this have to be implemented using any specific language or can I implement it using any language ?

from data-structures-algorithms.

0112CAMO avatar 0112CAMO commented on August 28, 2024

// C++ program to implement a queue using an array
#include <bits/stdc++.h>

using namespace std;

struct Queue {

int front, rear, capacity; 

int* queue; 

Queue(int c) 

{ 

    front = rear = 0; 

    capacity = c; 

    queue = new int; 

} 



~Queue() { delete[] queue; } 



// function to insert an element 

// at the rear of the queue 

void queueEnqueue(int data) 

{ 

    // check queue is full or not 

    if (capacity == rear) { 

        printf("\nQueue is full\n"); 

        return; 

    } 



    // insert element at the rear 

    else { 

        queue[rear] = data; 

        rear++; 

    } 

    return; 

} 



// function to delete an element 

// from the front of the queue 

void queueDequeue() 

{ 

    // if queue is empty 

    if (front == rear) { 

        printf("\nQueue is  empty\n"); 

        return; 

    } 



    // shift all the elements from index 2 till rear 

    // to the left by one 

    else { 

        for (int i = 0; i < rear - 1; i++) { 

            queue[i] = queue[i + 1]; 

        } 



        // decrement rear 

        rear--; 

    } 

    return; 

} 



// print queue elements 

void queueDisplay() 

{ 

    int i; 

    if (front == rear) { 

        printf("\nQueue is Empty\n"); 

        return; 

    } 



    // traverse front to rear and print elements 

    for (i = front; i < rear; i++) { 

        printf(" %d <-- ", queue[i]); 

    } 

    return; 

} 



// print front of queue 

void queueFront() 

{ 

    if (front == rear) { 

        printf("\nQueue is Empty\n"); 

        return; 

    } 

    printf("\nFront Element is: %d", queue[front]); 

    return; 

} 

};

// Driver code

int main(void)
{

// Create a queue of capacity 4 

Queue q(4); 



// print Queue elements 

q.queueDisplay(); 



// inserting elements in the queue 

q.queueEnqueue(20); 

q.queueEnqueue(30); 

q.queueEnqueue(40); 

q.queueEnqueue(50); 



// print Queue elements 

q.queueDisplay(); 



// insert element in the queue 

q.queueEnqueue(60); 



// print Queue elements 

q.queueDisplay(); 



q.queueDequeue(); 

q.queueDequeue(); 



printf("\n\nafter two node deletion\n\n"); 



// print Queue elements 

q.queueDisplay(); 



// print front of the queue 

q.queueFront(); 



return 0; 

}

from data-structures-algorithms.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.