Ans-1: While implementing a stack using a linear linked list (LLL) we use to insert the element at the beginning and also delete the element from the beginning, so top will point to the first element of the linked list or you can say that top will point to the node of the linked list which is also pointed by head pointer for ease of push and pop.
Ans-2:
a. front will point to the first element of the linked list i.e. head. in case of linear linked list (LLL)
b. rear will point to the last element of the linked list i.e. tail. in case of linear linked list (LLL)
c. rear will point to the last element of the circular linked list or you can say that rear will point to the node whose next pointer will point to the first node in the circular linked list (CLL).
Ans-3: Queue follows principle FIFO (First In First out)
So the order of removal is also the order of insertion that is:
10,20,30
Ans-4: Same as Ans-2
a. head
b. tail
Ans-5:
a. rear because then you can access data at front and rear without any linked list traversal because front is the node pointed by the rear node pointer field.
b. front data can be displayed by getting the address of the front node from the pointer field of the rear node and then accessing the data field of the front node.
c. rear data can be displayed simply by accessing the data field of the node pointed by the rear pointer.
Where does top point, when implementing a stack with a LLL? Queue ADT: 1· 2. Where...
Question1 ) The STL provides similiar classes called stack and queue, both of which gave functions called push and pop. Answer the following questions: 1.1) Does the push perform a different action in the stack class then in the queue class? Explain the answer. 1.2) Does the pop perform a different action in the stack class then in the queue class? Explain the answer. Question 2) 2.1) Suppose you are tasked with implementing a reverse queue in which elements are...
3. Some circular queue implementations use the mod operator % in enqueue and dequeue operations. Explain why this is inefficient. 4. If a queue is implemented using a singly linked list with a head and tail pointer, you should always insert at the tail and remove from the head. Explain why this is so. 5. What is a Priority Queue, and how does it differ from a standard queue? 6. Priority Queues are almost always implemented with an ordered data...
Your assignment is to create and test a class for a queue of objects. You may use any object class of your choice as the data for the queue. The instances of the class should have at least one field that distinguishes each instance from other instances of the class (key property, also called a key field). You should complete the software to implement and test your queue and submit the software along with a project report. Your queue class...
Study the "Queue as linked list simple example" posted in this module. Rewrite the code to use array instead of linked lists. Please do not change anything besides the data structure. Instead of linked list use an array. The functionality should remain exactly the same. LListQueue.cpp ///--------------------------------------------------------------- /// File: LListQueue.cpp /// Purpose: Implementation file for a demonstration of a queue /// implemented as an array. Data type: Character /// Programming Language: C++ ///--------------------------------------------------------------- #include "LListQueue.h" ///-------------------------------------------- /// Function: LListQueue() ///...
A limited-sized Queue ADT is an abstract data type that has a limit on the length of the queue. It can be created with a static array of size N, where N is the maximum length of the array. In C, this structure can be defined as follows: typedef struct {int * data;//array of the data on the queue//you may add other attributes here but use as few as possible} queue_t; Write an (efficient) pseudocode for the implementation of each...
Help me solve this in C++ Rewrite the code to use array instead of linked lists. Please do not change anything besides the data structure. Instead of linked list use an array. The functionality should remain exactly the same. You can prepare a class if you wish but it is not required. /** * Queue implementation using linked list C style implementation ( no OOP). */ #include <cstdio> #include <cstdlib> #include <climits> #include <iostream> #define CAPACITY 100 // Queue max...
Write a C++ program to implement Queue ADT using singly linked structure. The program includes the following: Define the Queue class template in the header file QueueLinked.h. // QueueLinked.h #ifndef QUEUE_H #define QUEUE_H #include <iostream> using namespace std; template <typename T> class Queue { public: // Constructor Queue(); //Desctructor ~Queue(); // Makes the queue to the empty state. void make_empty(); // Checks if the queue is empty. bool empty() const; // Inserts item at the end of the queue. void...
e. public class Queue { // Uses the correct Stack class from ME2
Ex 19 private Stack mStack; public Queue() { setStack(new Stack());
} public Queue enqueue(E pData) { getStack().push(pData); return
this; } public E dequeue() { return getStack().pop(); } public E
peek() { return getStack.peek(); } private Stack getStack() {
return mStack; } private void setStack(Stack pStack) { mStack =
pStack; } }
f. public class Queue extends Stack { // Uses the correct Stack
class from ME2 Ex...
HI USING C++ CAN YOU PLEASE PROGRAM THIS ASSIGNMENT AND ADD
COMMENTS:
stackARRAY:
#include<iostream>
#define SIZE 100
#define NO_ELEMENT -999999
using namespace std;
class Stack {
int arr[SIZE]; // array to store Stack elements
int top;
public:
Stack() {
top = -1;
}
void push(int); // push an element into Stack
int pop(); // pop the top element from Stack
int topElement(); // get the top element
void display(); // display Stack elements from top to bottom
};
void Stack...
What is the principle difference in behavior between a stack and a queue? a stack preserves the order in which items are added whereas a queue reverses order there is no difference a stack reverses the order in which items are added whereas a queue preserves order xa stack does nothing whereas a queue can preserve and reverse the order that items are added to it Fill in the blank in the following sentence with one of the answers listed....