EBK DATA STRUCTURES AND ALGORITHMS IN C
EBK DATA STRUCTURES AND ALGORITHMS IN C
4th Edition
ISBN: 9781285415017
Author: DROZDEK
Publisher: YUZU
Question
Book Icon
Chapter 4, Problem 7E
Program Plan Intro

Stack:

Stack is a container in which elements inserted and removed in LIFO (Last In First Out) manner.

  • The “top” is address of top element of stack.
  • Basic stack operations are given below:
    • push(): Insert an object into stack top.
    • pop(): Delete object in stack top.
    • topEl(): Get object in stack top.
    • isEmpty(): Check stack is empty or not.

Queue:

  • Queue is another data structure in which insertion and removal of elements are in FIFO(First In First Out) manner.
  • Basic operations are given below:
    • Enqueue(): Insert an element into back of queue
    • Dequeue(): Remove an item from front of queue
    • front(): Get first element of queue without removal of it.
    • isEmpty(): Check queue is empty or not.

Blurred answer
Students have asked these similar questions
#include <iostream> usingnamespace std; class Queue {     int size;     int* queue;         public:     Queue(){         size = 0;         queue = new int[100];     }     void add(int data){         queue[size]= data;         size++;     }     void remove(){         if(size ==0){             cout <<"Queue is empty"<<endl;             return;         }         else{             for(int i =0; i < size -1; i++){                 queue[i]= queue[i +1];             }             size--;         }     }     void print(){         if(size ==0){             cout <<"Queue is empty"<<endl;             return;         }         for(int i =0; i < size; i++){             cout<<queue[i]<<" <- ";         }         cout << endl;     }     //your code goes here     }; int main(){     Queue q1;     q1.add(42); q1.add(2); q1.add(8);  q1.add(1);     Queue q2;     q2.add(3); q2.add(66); q2.add(128);  q2.add(5);     Queue q3 = q1+q2;     q3.print();…
class Queue {       private static int front, rear, capacity;       private static int queue[];           Queue(int size)        {               front = rear = 0;               capacity = size;               queue = new int[capacity];           }        // insert an element into the queue      static void queueEnqueue(int item)    {           // check if the queue is full          if (capacity == rear)         {               System.out.printf("\nQueue is full\n");               return;           }                // insert element at the rear           else {               queue[rear] = item;               rear++;           }           return;       }            //remove an element from the queue      static void queueDequeue()      {           // check if queue is empty           if (front == rear)        {               System.out.printf("\nQueue is empty\n");               return;           }                // shift elements to the right by one place uptil rear           else {…
1 Implement a Queue Data Structure specifically to store integer data using a Singly Linked List. 2 The data members should be private. 3 You need to implement the following public functions: 4 1. Constructor: 5 It initialises the data members as required. 6 7 8 2. enqueue(data) : This function should take one argument of type integer. It enqueues the element into the queue and returns nothing. 3. dequeue(): It dequeues/removes the element from the front of the queue and in turn, returns the element being dequeued or removed. In case the queue is empty, it r 4. front (): 10 11 It returns the element being kept at the front of the queue. In case the queue is empty, it returns -1. 12 5. getSize(): 13 It returns the size of the queue at any given instance of time. 14 6. 1sEmpty(): 15 It returns a boolean value indicating whether the queue is empty or not. 16 Operations Performed on the Stack: 17 Query-1 (Denoted by an integer 1): Enqueues an integer data to the queue. 18 19 Query-2…
Knowledge Booster
Background pattern image
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning