SlideShare a Scribd company logo
please tell me what lines do i alter to make this stack a queue. tell me what to change it to
#include
using namespace std;
const int MAXSIZE = 100; // Maximum size of the stack
class Stack {
private:
int top; // Index of the top element in the stack
int data[MAXSIZE]; // Array to hold the stack elements
public:
Stack () {
top = -1; // Initialize the top index to -1 to indicate an empty stack
}
bool push (int val) {
if (top == MAXSIZE - 1) { // Stack is full
return false;
}
top++; // Increment the top index
data[top] = val; // Add the new element to the top of the stack
return true;
}
bool pop() {
if (top == -1) { // Stack is empty
return false;
}
top--; // Decrement the top index to remove the top element
return true;
}
bool peek(int& val) {
if (top == -1) { // Stack is empty
return false;
}
val = data[top]; // Return the top element without removing it.
return true;
}
void display(ostream& out) {
if (top == -1) { // Stack is empty
out << "Empty stack" << endl;
return;
}
for (int i = top; i >= 0; i--) { // Loop through the stack elements from top to bottom
out << data[i] << "";
}
out << endl;
}
};
int main() {
Stack S;
int tmp;
S.push (5);
S. peek (tmp);
cout << tmp << endl;
S.push (33);
S.push (1);
S.push (7);
S.peek (tmp);
cout << tmp << endl;
S.push (33) ;
S.push (12);
S.display ( cout );
S.pop ( );
S.display ( cout );
S.push (14);
S.display ( cout );
S.pop ( ) ;
S.pop ( );
S.display ( cout );
S.pop ( );
S. pop ( ) ;
S.display ( cout );
S.peek (tmp);
cout << tmp << endl;
}
#include
using namespace std;
const int MAXSIZE = 100; // Maximum size of the stack
class Stack {
private:
int top; // Index of the top element in the stack
int data[MAXSIZE]; // Array to hold the stack elements
public:
Stack () {
top = -1; // Initialize the top index to -1 to indicate an empty stack
}
bool push (int val) {
if (top == MAXSIZE - 1) { // Stack is full
return false;
}
top++; // Increment the top index
data[top] = val; // Add the new element to the top of the stack
return true;
}
bool pop() {
if (top == -1) { // Stack is empty
return false;
}
top--; // Decrement the top index to remove the top element
return true;
}
bool peek(int& val) {
if (top == -1) { // Stack is empty
return false;
}
val = data[top]; // Return the top element without removing it.
return true;
}
void display(ostream& out) {
if (top == -1) { // Stack is empty
out << "Empty stack" << endl;
return;
}
for (int i = top; i >= 0; i--) { // Loop through the stack elements from top to bottom
out << data[i] << "";
}
out << endl;
}
};
int main() {
Stack S;
int tmp;
S.push (5);
S. peek (tmp);
cout << tmp << endl;
S.push (33);
S.push (1);
S.push (7);
S.peek (tmp);
cout << tmp << endl;
S.push (33) ;
S.push (12);
S.display ( cout );
S.pop ( );
S.display ( cout );
S.push (14);
S.display ( cout );
S.pop ( ) ;
S.pop ( );
S.display ( cout );
S.pop ( );
S. pop ( ) ;
S.display ( cout );
S.peek (tmp);
cout << tmp << endl;
}
#include
using namespace std;
const int MAXSIZE = 100; // Maximum size of the stack
class Stack {
private:
int top; // Index of the top element in the stack
int data[MAXSIZE]; // Array to hold the stack elements
public:
Stack () {
top = -1; // Initialize the top index to -1 to indicate an empty stack
}
bool push (int val) {
if (top == MAXSIZE - 1) { // Stack is full
return false;
}
top++; // Increment the top index
data[top] = val; // Add the new element to the top of the stack
return true;
}
bool pop() {
if (top == -1) { // Stack is empty
return false;
}
top--; // Decrement the top index to remove the top element
return true;
}
bool peek(int& val) {
if (top == -1) { // Stack is empty
return false;
}
val = data[top]; // Return the top element without removing it.
return true;
}
void display(ostream& out) {
if (top == -1) { // Stack is empty
out << "Empty stack" << endl;
return;
}
for (int i = top; i >= 0; i--) { // Loop through the stack elements from top to bottom
out << data[i] << "";
}
out << endl;
}
};
int main() {
Stack S;
int tmp;
S.push (5);
S. peek (tmp);
cout << tmp << endl;
S.push (33);
S.push (1);
S.push (7);
S.peek (tmp);
cout << tmp << endl;
S.push (33) ;
S.push (12);
S.display ( cout );
S.pop ( );
S.display ( cout );
S.push (14);
S.display ( cout );
S.pop ( ) ;
S.pop ( );
S.display ( cout );
S.pop ( );
S. pop ( ) ;
S.display ( cout );
S.peek (tmp);
cout << tmp << endl;
}

More Related Content

PPTX
PPTX
Stack and its applications
PDF
Were writing code for a project that dynamically allocates an arra.pdf
DOCX
here is the starter code     File   main.c  Au.docx
PDF
STLStack.pdf
PPT
Stacks
PPT
03 stacks and_queues_using_arrays
PPT
Stack queue
Stack and its applications
Were writing code for a project that dynamically allocates an arra.pdf
here is the starter code     File   main.c  Au.docx
STLStack.pdf
Stacks
03 stacks and_queues_using_arrays
Stack queue

Similar to please tell me what lines do i alter to make this stack a queue. tel.pdf (20)

PPT
Stack queue
PPT
Stack queue
PPT
Stack queue
PPT
Stack queue
PPT
Stack queue
PPT
Stack queue
PPTX
Stacks in c++
PPT
Algo>Stacks
PPT
Stack and queue
PPT
Lec 4 Stack of Data Structures & Algorithms
DOCX
Add functions push(int n- Deque &dq) and pop(Deque &dq)- Functions pus.docx
PDF
What is Stack, Its Operations, Queue, Circular Queue, Priority Queue
PDF
later we create a specialstack class ,which inherits from stack cl.pdf
PPTX
My lecture stack_queue_operation
PDF
Chapter 5 Stack and Queue.pdf
PPT
PPT
Ch03_stacks_and_queues.ppt
PPT
The Stack in data structures .ppt
PDF
solution in c++program Program to implement a queue using two .pdf
PDF
1- The design of a singly-linked list below is a picture of the functi (1).pdf
Stack queue
Stack queue
Stack queue
Stack queue
Stack queue
Stack queue
Stacks in c++
Algo>Stacks
Stack and queue
Lec 4 Stack of Data Structures & Algorithms
Add functions push(int n- Deque &dq) and pop(Deque &dq)- Functions pus.docx
What is Stack, Its Operations, Queue, Circular Queue, Priority Queue
later we create a specialstack class ,which inherits from stack cl.pdf
My lecture stack_queue_operation
Chapter 5 Stack and Queue.pdf
Ch03_stacks_and_queues.ppt
The Stack in data structures .ppt
solution in c++program Program to implement a queue using two .pdf
1- The design of a singly-linked list below is a picture of the functi (1).pdf

More from agarshailenterprises (20)

PDF
Please, correct the following ELM codemodule Main exposing (..).pdf
PDF
pls help! 1. Understanding the implications of taxes on welfare The .pdf
PDF
Please write one paragraph below demonstratingDecide on a hedging.pdf
PDF
Please use these instructions to help.Use the flexbox layout mode .pdf
PDF
Please use these instructions to help. Please only edit the CSS, and.pdf
PDF
Please write a program with a simple INTERFACE. Provide a design for.pdf
PDF
Please show how to do these calculation based on 2021 Starbucks An.pdf
PDF
Please review the two journals on Endogenous growth Theory. 1. Shaw..pdf
PDF
Please read the case study below and answer the following questions .pdf
PDF
Please modify the following code in C. Make sure your code matches t.pdf
PDF
Please provide a detailed explanation as to how you get to the answe.pdf
PDF
please I need explanation for the whole queston and why the answer I.pdf
PDF
Please help with part b. Taylor Talbot receives wages amounting to .pdf
PDF
Please explain how to find The heights of a certain population of co.pdf
PDF
Please help me get the right answers. The Economist publishes a year.pdf
PDF
Please explain in detail. Thank you! 2. Consider two independent sta.pdf
PDF
Please explain in detail. Thank you! 10. The joint probability distr.pdf
PDF
please help 3. Which of the four classification schemes (suggested b.pdf
PDF
Please expound on the specific details and examples of each componen.pdf
PDF
please dont solve 1) [12 marks] Suppose Y1 and Y2 be independent.pdf
Please, correct the following ELM codemodule Main exposing (..).pdf
pls help! 1. Understanding the implications of taxes on welfare The .pdf
Please write one paragraph below demonstratingDecide on a hedging.pdf
Please use these instructions to help.Use the flexbox layout mode .pdf
Please use these instructions to help. Please only edit the CSS, and.pdf
Please write a program with a simple INTERFACE. Provide a design for.pdf
Please show how to do these calculation based on 2021 Starbucks An.pdf
Please review the two journals on Endogenous growth Theory. 1. Shaw..pdf
Please read the case study below and answer the following questions .pdf
Please modify the following code in C. Make sure your code matches t.pdf
Please provide a detailed explanation as to how you get to the answe.pdf
please I need explanation for the whole queston and why the answer I.pdf
Please help with part b. Taylor Talbot receives wages amounting to .pdf
Please explain how to find The heights of a certain population of co.pdf
Please help me get the right answers. The Economist publishes a year.pdf
Please explain in detail. Thank you! 2. Consider two independent sta.pdf
Please explain in detail. Thank you! 10. The joint probability distr.pdf
please help 3. Which of the four classification schemes (suggested b.pdf
Please expound on the specific details and examples of each componen.pdf
please dont solve 1) [12 marks] Suppose Y1 and Y2 be independent.pdf

Recently uploaded (20)

PDF
A systematic review of self-coping strategies used by university students to ...
PPTX
Microbial diseases, their pathogenesis and prophylaxis
PDF
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
PPTX
Tissue processing ( HISTOPATHOLOGICAL TECHNIQUE
PDF
RTP_AR_KS1_Tutor's Guide_English [FOR REPRODUCTION].pdf
PDF
Anesthesia in Laparoscopic Surgery in India
PPTX
Cell Structure & Organelles in detailed.
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PDF
GENETICS IN BIOLOGY IN SECONDARY LEVEL FORM 3
PDF
O7-L3 Supply Chain Operations - ICLT Program
PDF
Complications of Minimal Access Surgery at WLH
PPTX
GDM (1) (1).pptx small presentation for students
PPTX
Lesson notes of climatology university.
PDF
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
PDF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
PPTX
Orientation - ARALprogram of Deped to the Parents.pptx
PPTX
Introduction-to-Literarature-and-Literary-Studies-week-Prelim-coverage.pptx
PPTX
Final Presentation General Medicine 03-08-2024.pptx
A systematic review of self-coping strategies used by university students to ...
Microbial diseases, their pathogenesis and prophylaxis
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
Tissue processing ( HISTOPATHOLOGICAL TECHNIQUE
RTP_AR_KS1_Tutor's Guide_English [FOR REPRODUCTION].pdf
Anesthesia in Laparoscopic Surgery in India
Cell Structure & Organelles in detailed.
O5-L3 Freight Transport Ops (International) V1.pdf
2.FourierTransform-ShortQuestionswithAnswers.pdf
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
GENETICS IN BIOLOGY IN SECONDARY LEVEL FORM 3
O7-L3 Supply Chain Operations - ICLT Program
Complications of Minimal Access Surgery at WLH
GDM (1) (1).pptx small presentation for students
Lesson notes of climatology university.
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
Orientation - ARALprogram of Deped to the Parents.pptx
Introduction-to-Literarature-and-Literary-Studies-week-Prelim-coverage.pptx
Final Presentation General Medicine 03-08-2024.pptx

please tell me what lines do i alter to make this stack a queue. tel.pdf

  • 1. please tell me what lines do i alter to make this stack a queue. tell me what to change it to #include using namespace std; const int MAXSIZE = 100; // Maximum size of the stack class Stack { private: int top; // Index of the top element in the stack int data[MAXSIZE]; // Array to hold the stack elements public: Stack () { top = -1; // Initialize the top index to -1 to indicate an empty stack } bool push (int val) { if (top == MAXSIZE - 1) { // Stack is full return false; } top++; // Increment the top index data[top] = val; // Add the new element to the top of the stack return true; } bool pop() { if (top == -1) { // Stack is empty return false; }
  • 2. top--; // Decrement the top index to remove the top element return true; } bool peek(int& val) { if (top == -1) { // Stack is empty return false; } val = data[top]; // Return the top element without removing it. return true; } void display(ostream& out) { if (top == -1) { // Stack is empty out << "Empty stack" << endl; return; } for (int i = top; i >= 0; i--) { // Loop through the stack elements from top to bottom out << data[i] << ""; } out << endl; } }; int main() { Stack S; int tmp; S.push (5); S. peek (tmp); cout << tmp << endl; S.push (33); S.push (1); S.push (7); S.peek (tmp); cout << tmp << endl; S.push (33) ; S.push (12);
  • 3. S.display ( cout ); S.pop ( ); S.display ( cout ); S.push (14); S.display ( cout ); S.pop ( ) ; S.pop ( ); S.display ( cout ); S.pop ( ); S. pop ( ) ; S.display ( cout ); S.peek (tmp); cout << tmp << endl; } #include using namespace std; const int MAXSIZE = 100; // Maximum size of the stack class Stack { private: int top; // Index of the top element in the stack int data[MAXSIZE]; // Array to hold the stack elements public: Stack () { top = -1; // Initialize the top index to -1 to indicate an empty stack }
  • 4. bool push (int val) { if (top == MAXSIZE - 1) { // Stack is full return false; } top++; // Increment the top index data[top] = val; // Add the new element to the top of the stack return true; } bool pop() { if (top == -1) { // Stack is empty return false; } top--; // Decrement the top index to remove the top element return true; } bool peek(int& val) { if (top == -1) { // Stack is empty return false; } val = data[top]; // Return the top element without removing it. return true; } void display(ostream& out) { if (top == -1) { // Stack is empty out << "Empty stack" << endl; return; } for (int i = top; i >= 0; i--) { // Loop through the stack elements from top to bottom out << data[i] << ""; } out << endl; }
  • 5. }; int main() { Stack S; int tmp; S.push (5); S. peek (tmp); cout << tmp << endl; S.push (33); S.push (1); S.push (7); S.peek (tmp); cout << tmp << endl; S.push (33) ; S.push (12); S.display ( cout ); S.pop ( ); S.display ( cout ); S.push (14); S.display ( cout ); S.pop ( ) ; S.pop ( ); S.display ( cout ); S.pop ( ); S. pop ( ) ; S.display ( cout ); S.peek (tmp); cout << tmp << endl; } #include using namespace std; const int MAXSIZE = 100; // Maximum size of the stack class Stack {
  • 6. private: int top; // Index of the top element in the stack int data[MAXSIZE]; // Array to hold the stack elements public: Stack () { top = -1; // Initialize the top index to -1 to indicate an empty stack } bool push (int val) { if (top == MAXSIZE - 1) { // Stack is full return false; } top++; // Increment the top index data[top] = val; // Add the new element to the top of the stack return true; } bool pop() { if (top == -1) { // Stack is empty return false; } top--; // Decrement the top index to remove the top element return true; } bool peek(int& val) { if (top == -1) { // Stack is empty return false; } val = data[top]; // Return the top element without removing it. return true; } void display(ostream& out) {
  • 7. if (top == -1) { // Stack is empty out << "Empty stack" << endl; return; } for (int i = top; i >= 0; i--) { // Loop through the stack elements from top to bottom out << data[i] << ""; } out << endl; } }; int main() { Stack S; int tmp; S.push (5); S. peek (tmp); cout << tmp << endl; S.push (33); S.push (1); S.push (7); S.peek (tmp); cout << tmp << endl; S.push (33) ; S.push (12); S.display ( cout ); S.pop ( ); S.display ( cout ); S.push (14); S.display ( cout ); S.pop ( ) ; S.pop ( ); S.display ( cout ); S.pop ( ); S. pop ( ) ; S.display ( cout ); S.peek (tmp); cout << tmp << endl;
  • 8. }