Question

In: Computer Science

Write C++ programs to implement Queue ADT data structure using Linked List.

Write C++ programs to implement Queue ADT data structure using Linked List.

Solutions

Expert Solution

#include<iostream>

#include<stdio.h>

#include<conio.h>

using namespace std;

struct node

{

    int data;

    node *next;

}*front = NULL,*rear = NULL,*p = NULL,*np = NULL;

void push(int x)

{

    np = new node;

    np->data = x;

    np->next = NULL;

    if(front == NULL)

    {

        front = rear = np;

        rear->next = NULL;

    }

    else

    {

        rear->next = np;

        rear = np;

        rear->next = NULL;

    }

}

int remove()

{

    int x;

    if(front == NULL)

    {

        cout<<"Empty Queue\n";

    }

    else

    {

        p = front;

        x = p->data;

        front = front->next;

        delete(p);

        return(x);

    }

}

int main()

{

    int n,c = 0,x;

    cout<<"Enter the number of values to be pushed in queue\n";

    cin>>n;

    while (c < n)

    {

   cout<<"Enter the value to be entered in queue\n";

   cin>>x;

        push(x);

        c++;

     }

     cout<<"\n\nELIMINATED VALUES\n\n";

     while(true)

     {

        if (front != NULL)

            cout<<remove()<<endl;

        else

            break;

     }

     getch();

}


Related Solutions

In C++, Implement the queue ADT with a singly linked list
In C++, Implement the queue ADT with a singly linked list
Using the linked list abstract data type “Queue ADT”, write a menu dirven user interfece to...
Using the linked list abstract data type “Queue ADT”, write a menu dirven user interfece to teach each of the operations in the ADT. Any errors discovered during the processing should be printed as a part of the test result. Please Use C++ language.
C++ Data Structures: Implement a Stack and a Queue using Linked list In this lab you...
C++ Data Structures: Implement a Stack and a Queue using Linked list In this lab you will implement the functionality of a stack and a queue using a linked list. Your program must use of the declaration of the Stack and Queue class in Stack.h and Queue.h You have to implement the functionalities of queue (enq, deq, displayQueue) in a file called Queue.cpp. All the functions in Queue.cpp should follow the prototypes declared in Queue.h. Your code should make use...
Show how circular linked list can be useful to implement Circular Queue (CQ) ADT (Abstract Data...
Show how circular linked list can be useful to implement Circular Queue (CQ) ADT (Abstract Data Type). Compare and contrast with array based implementation. Which one would you recommend to implement CQ and why
1. Implement the graph ADT using the adjacency list structure. 2. Implement the graph ADT using...
1. Implement the graph ADT using the adjacency list structure. 2. Implement the graph ADT using the adjacency matrix structure. LANGUAGE IS IN JAVA Comment for any questions Data structures and algorithms
IN JAVA LANGUAGE Linked List-Based Queue Implementation Implement Queue using a Linked List. Use the language...
IN JAVA LANGUAGE Linked List-Based Queue Implementation Implement Queue using a Linked List. Use the language library LinkedList Queue methods will call the LinkedList methods You can use string as the object Instead of using an array, as the QueueLab did, here you will use a Linked List from your language's library. Implement all the methods of Stack : enqueue(), dequeue(), size(), printQueue(), etc, using calls to the linked list methods that correspond to the actions need. In the array...
Give a complete implementation of the queue ADT using a singly linked list that includes a...
Give a complete implementation of the queue ADT using a singly linked list that includes a header sentinel (in Python).
write a java program to Implement a Priority Queue using a linked list. Include a main...
write a java program to Implement a Priority Queue using a linked list. Include a main method demonstrating enqueuing and dequeuing several numbers, printing the list contents for each.
Write a code to implement a python queue class using a linked list. use these operations...
Write a code to implement a python queue class using a linked list. use these operations isEmpty • enqueue. • dequeue    • size Time and compare the performances of the operations ( this is optional but I would appreciate it)
Implement the ADT character string as the class LinkedString by using a linked list of characters....
Implement the ADT character string as the class LinkedString by using a linked list of characters. Include the following LinkedString constructors and methods: LinkedString(char[] value) Allocates a new character linked list so that it represents the sequence of characters currently contained in the character array argument. LinkedString(String original) Initializes a new character linked list so that it represents the same sequence of characters as the argument. char charAt(int index) Returns the char value at the specified index. The first character...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT