SlideShare a Scribd company logo
Explain what does the following function do void foo (Stack *s) { while(!s rightarrow
isEmpty()) { cout
Solution
This function is written to call a stack which is a recursive data structure. A stack is basically a
collection of objects which is based on LIFO(Last In First Out) where the element that is inserted
at the last will be deleted first from the stack. To insert an element we use PUSH in a stack and
to delete we use POP.
TOP represents the top element in the stack.
In this program, function foo calls a stack s and in the while loop there is a condition (!s-
>isEmpty()) which checks whether the stack is empty or not. If the stack is not empty then the
program prints the top element of the stack (cout<top()) and then s->pop(); means that after
printing the top element pop opertaion is being called which deletes the top most element of the
stack.
So this program will delete all the elements of the stack until the stack is empty.
Example- the stack has elements inserted as 10,9,8,7. So the program will print 10,9,8,7 and will
delete them one by one. First 10 will be deleted then 9 and so on as stack follows a LIFO
structure.

More Related Content

Similar to Explain what does the following function do void foo (Stack s) { .pdf

Stack and its operation implemented with array new - Copy.pptx
Stack and its operation implemented with array new - Copy.pptxStack and its operation implemented with array new - Copy.pptx
Stack and its operation implemented with array new - Copy.pptx
Shivam Kumar
 

Similar to Explain what does the following function do void foo (Stack s) { .pdf (20)

Data structure lab manual
Data structure lab manualData structure lab manual
Data structure lab manual
 
Stacks
StacksStacks
Stacks
 
Stack operation algorithms with example
Stack operation algorithms with exampleStack operation algorithms with example
Stack operation algorithms with example
 
Applicationofstack by Ali F.RAshid
Applicationofstack  by Ali F.RAshid Applicationofstack  by Ali F.RAshid
Applicationofstack by Ali F.RAshid
 
Application of Stack - Yadraj Meena
Application of Stack - Yadraj MeenaApplication of Stack - Yadraj Meena
Application of Stack - Yadraj Meena
 
Module 2 ppt.pptx
Module 2 ppt.pptxModule 2 ppt.pptx
Module 2 ppt.pptx
 
Stack and its operation implemented with array new - Copy.pptx
Stack and its operation implemented with array new - Copy.pptxStack and its operation implemented with array new - Copy.pptx
Stack and its operation implemented with array new - Copy.pptx
 
Stack converted
Stack convertedStack converted
Stack converted
 
16-StacksQueuesCVCJUCGTCXYFRSTTIUGIUFTY.ppt
16-StacksQueuesCVCJUCGTCXYFRSTTIUGIUFTY.ppt16-StacksQueuesCVCJUCGTCXYFRSTTIUGIUFTY.ppt
16-StacksQueuesCVCJUCGTCXYFRSTTIUGIUFTY.ppt
 
stack-Intro.pptx
stack-Intro.pptxstack-Intro.pptx
stack-Intro.pptx
 
Stacks,queues,linked-list
Stacks,queues,linked-listStacks,queues,linked-list
Stacks,queues,linked-list
 
What is Stack? Application of Stack
What is Stack? Application of StackWhat is Stack? Application of Stack
What is Stack? Application of Stack
 
Why does the stack use a FILO (first in last out) schemeSolutio.pdf
Why does the stack use a FILO (first in last out) schemeSolutio.pdfWhy does the stack use a FILO (first in last out) schemeSolutio.pdf
Why does the stack use a FILO (first in last out) schemeSolutio.pdf
 
Stack
StackStack
Stack
 
stacks and queues
stacks and queuesstacks and queues
stacks and queues
 
DATA STRUCTURE - STACK
DATA STRUCTURE - STACKDATA STRUCTURE - STACK
DATA STRUCTURE - STACK
 
Stacks Data structure.pptx
Stacks Data structure.pptxStacks Data structure.pptx
Stacks Data structure.pptx
 
04 stacks
04 stacks04 stacks
04 stacks
 
stacks and queues
stacks and queuesstacks and queues
stacks and queues
 
In C++ a function used to put data into a stack is typically called a.docx
In C++ a function used to put data into a stack is typically called a.docxIn C++ a function used to put data into a stack is typically called a.docx
In C++ a function used to put data into a stack is typically called a.docx
 

More from meerobertsonheyde608

Consider a 4-Link robot manipulator shown below. Use the forward kine.pdf
Consider a 4-Link robot manipulator shown below. Use the forward kine.pdfConsider a 4-Link robot manipulator shown below. Use the forward kine.pdf
Consider a 4-Link robot manipulator shown below. Use the forward kine.pdf
meerobertsonheyde608
 
Conduct some basic research on the recessive disorder Albinism.Des.pdf
Conduct some basic research on the recessive disorder Albinism.Des.pdfConduct some basic research on the recessive disorder Albinism.Des.pdf
Conduct some basic research on the recessive disorder Albinism.Des.pdf
meerobertsonheyde608
 
Answer the questions below based on the database model found on the n.pdf
Answer the questions below based on the database model found on the n.pdfAnswer the questions below based on the database model found on the n.pdf
Answer the questions below based on the database model found on the n.pdf
meerobertsonheyde608
 
What scientific mechanism for evolution did Charles Darwin and Alfred.pdf
What scientific mechanism for evolution did Charles Darwin and Alfred.pdfWhat scientific mechanism for evolution did Charles Darwin and Alfred.pdf
What scientific mechanism for evolution did Charles Darwin and Alfred.pdf
meerobertsonheyde608
 
What are the genetic differences between a processed pseudogene and .pdf
What are the genetic differences between a processed pseudogene and .pdfWhat are the genetic differences between a processed pseudogene and .pdf
What are the genetic differences between a processed pseudogene and .pdf
meerobertsonheyde608
 
True or False_____ Cells Composed of chemicals and structures, ma.pdf
True or False_____ Cells Composed of chemicals and structures, ma.pdfTrue or False_____ Cells Composed of chemicals and structures, ma.pdf
True or False_____ Cells Composed of chemicals and structures, ma.pdf
meerobertsonheyde608
 
The picture above shows the life cycle of a moss. Mark all true stat.pdf
The picture above shows the life cycle of a moss. Mark all true stat.pdfThe picture above shows the life cycle of a moss. Mark all true stat.pdf
The picture above shows the life cycle of a moss. Mark all true stat.pdf
meerobertsonheyde608
 
State some successful predictions from Einsteins theory of special.pdf
State some successful predictions from Einsteins theory of special.pdfState some successful predictions from Einsteins theory of special.pdf
State some successful predictions from Einsteins theory of special.pdf
meerobertsonheyde608
 
Problem 14-1A On January 1, 2017, Geffrey Corporation had the followi.pdf
Problem 14-1A On January 1, 2017, Geffrey Corporation had the followi.pdfProblem 14-1A On January 1, 2017, Geffrey Corporation had the followi.pdf
Problem 14-1A On January 1, 2017, Geffrey Corporation had the followi.pdf
meerobertsonheyde608
 

More from meerobertsonheyde608 (20)

Discuss the seven factors that analysts consider where selecting a f.pdf
Discuss the seven factors that analysts consider where selecting a f.pdfDiscuss the seven factors that analysts consider where selecting a f.pdf
Discuss the seven factors that analysts consider where selecting a f.pdf
 
Consider a 4-Link robot manipulator shown below. Use the forward kine.pdf
Consider a 4-Link robot manipulator shown below. Use the forward kine.pdfConsider a 4-Link robot manipulator shown below. Use the forward kine.pdf
Consider a 4-Link robot manipulator shown below. Use the forward kine.pdf
 
Conduct some basic research on the recessive disorder Albinism.Des.pdf
Conduct some basic research on the recessive disorder Albinism.Des.pdfConduct some basic research on the recessive disorder Albinism.Des.pdf
Conduct some basic research on the recessive disorder Albinism.Des.pdf
 
calculate the next annual dividend payment for stock currently selli.pdf
calculate the next annual dividend payment for stock currently selli.pdfcalculate the next annual dividend payment for stock currently selli.pdf
calculate the next annual dividend payment for stock currently selli.pdf
 
Bookmark On the Isle of Man off the coast of Ireland, a curious cat .pdf
Bookmark On the Isle of Man off the coast of Ireland, a curious cat .pdfBookmark On the Isle of Man off the coast of Ireland, a curious cat .pdf
Bookmark On the Isle of Man off the coast of Ireland, a curious cat .pdf
 
Answer the questions below based on the database model found on the n.pdf
Answer the questions below based on the database model found on the n.pdfAnswer the questions below based on the database model found on the n.pdf
Answer the questions below based on the database model found on the n.pdf
 
You are reviewing basic network protocols with a new tech in your co.pdf
You are reviewing basic network protocols with a new tech in your co.pdfYou are reviewing basic network protocols with a new tech in your co.pdf
You are reviewing basic network protocols with a new tech in your co.pdf
 
Why might a gene have more than 2 different allelesa.     DNA seq.pdf
Why might a gene have more than 2 different allelesa.     DNA seq.pdfWhy might a gene have more than 2 different allelesa.     DNA seq.pdf
Why might a gene have more than 2 different allelesa.     DNA seq.pdf
 
Which of the following are true statementsI. sin2+cos2=1II. sec.pdf
Which of the following are true statementsI. sin2+cos2=1II. sec.pdfWhich of the following are true statementsI. sin2+cos2=1II. sec.pdf
Which of the following are true statementsI. sin2+cos2=1II. sec.pdf
 
What scientific mechanism for evolution did Charles Darwin and Alfred.pdf
What scientific mechanism for evolution did Charles Darwin and Alfred.pdfWhat scientific mechanism for evolution did Charles Darwin and Alfred.pdf
What scientific mechanism for evolution did Charles Darwin and Alfred.pdf
 
What is the main difference between doing business process analysis .pdf
What is the main difference between doing business process analysis .pdfWhat is the main difference between doing business process analysis .pdf
What is the main difference between doing business process analysis .pdf
 
What are the genetic differences between a processed pseudogene and .pdf
What are the genetic differences between a processed pseudogene and .pdfWhat are the genetic differences between a processed pseudogene and .pdf
What are the genetic differences between a processed pseudogene and .pdf
 
True or False_____ Cells Composed of chemicals and structures, ma.pdf
True or False_____ Cells Composed of chemicals and structures, ma.pdfTrue or False_____ Cells Composed of chemicals and structures, ma.pdf
True or False_____ Cells Composed of chemicals and structures, ma.pdf
 
The picture above shows the life cycle of a moss. Mark all true stat.pdf
The picture above shows the life cycle of a moss. Mark all true stat.pdfThe picture above shows the life cycle of a moss. Mark all true stat.pdf
The picture above shows the life cycle of a moss. Mark all true stat.pdf
 
The conversion of pyruvate to acetyl-CoA. A. requires the addition o.pdf
The conversion of pyruvate to acetyl-CoA. A. requires the addition o.pdfThe conversion of pyruvate to acetyl-CoA. A. requires the addition o.pdf
The conversion of pyruvate to acetyl-CoA. A. requires the addition o.pdf
 
Suppose S is a set of n + 1 integers. Prove that there exist distinct.pdf
Suppose S is a set of n + 1 integers. Prove that there exist distinct.pdfSuppose S is a set of n + 1 integers. Prove that there exist distinct.pdf
Suppose S is a set of n + 1 integers. Prove that there exist distinct.pdf
 
Structural features of fungi Complete the following paragraph to desc.pdf
Structural features of fungi Complete the following paragraph to desc.pdfStructural features of fungi Complete the following paragraph to desc.pdf
Structural features of fungi Complete the following paragraph to desc.pdf
 
State some successful predictions from Einsteins theory of special.pdf
State some successful predictions from Einsteins theory of special.pdfState some successful predictions from Einsteins theory of special.pdf
State some successful predictions from Einsteins theory of special.pdf
 
QUESTION 7 Forward and futures markets provide insurance or hedging a.pdf
QUESTION 7 Forward and futures markets provide insurance or hedging a.pdfQUESTION 7 Forward and futures markets provide insurance or hedging a.pdf
QUESTION 7 Forward and futures markets provide insurance or hedging a.pdf
 
Problem 14-1A On January 1, 2017, Geffrey Corporation had the followi.pdf
Problem 14-1A On January 1, 2017, Geffrey Corporation had the followi.pdfProblem 14-1A On January 1, 2017, Geffrey Corporation had the followi.pdf
Problem 14-1A On January 1, 2017, Geffrey Corporation had the followi.pdf
 

Recently uploaded

Industrial Training Report- AKTU Industrial Training Report
Industrial Training Report- AKTU Industrial Training ReportIndustrial Training Report- AKTU Industrial Training Report
Industrial Training Report- AKTU Industrial Training Report
Avinash Rai
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
joachimlavalley1
 

Recently uploaded (20)

Matatag-Curriculum and the 21st Century Skills Presentation.pptx
Matatag-Curriculum and the 21st Century Skills Presentation.pptxMatatag-Curriculum and the 21st Century Skills Presentation.pptx
Matatag-Curriculum and the 21st Century Skills Presentation.pptx
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
 
Jose-Rizal-and-Philippine-Nationalism-National-Symbol-2.pptx
Jose-Rizal-and-Philippine-Nationalism-National-Symbol-2.pptxJose-Rizal-and-Philippine-Nationalism-National-Symbol-2.pptx
Jose-Rizal-and-Philippine-Nationalism-National-Symbol-2.pptx
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
 
UNIT – IV_PCI Complaints: Complaints and evaluation of complaints, Handling o...
UNIT – IV_PCI Complaints: Complaints and evaluation of complaints, Handling o...UNIT – IV_PCI Complaints: Complaints and evaluation of complaints, Handling o...
UNIT – IV_PCI Complaints: Complaints and evaluation of complaints, Handling o...
 
Industrial Training Report- AKTU Industrial Training Report
Industrial Training Report- AKTU Industrial Training ReportIndustrial Training Report- AKTU Industrial Training Report
Industrial Training Report- AKTU Industrial Training Report
 
The Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve ThomasonThe Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve Thomason
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
 
Danh sách HSG Bộ môn cấp trường - Cấp THPT.pdf
Danh sách HSG Bộ môn cấp trường - Cấp THPT.pdfDanh sách HSG Bộ môn cấp trường - Cấp THPT.pdf
Danh sách HSG Bộ môn cấp trường - Cấp THPT.pdf
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
 
Sectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdfSectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdf
 
Introduction to Quality Improvement Essentials
Introduction to Quality Improvement EssentialsIntroduction to Quality Improvement Essentials
Introduction to Quality Improvement Essentials
 
How to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERPHow to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERP
 
Salient features of Environment protection Act 1986.pptx
Salient features of Environment protection Act 1986.pptxSalient features of Environment protection Act 1986.pptx
Salient features of Environment protection Act 1986.pptx
 
Fish and Chips - have they had their chips
Fish and Chips - have they had their chipsFish and Chips - have they had their chips
Fish and Chips - have they had their chips
 

Explain what does the following function do void foo (Stack s) { .pdf

  • 1. Explain what does the following function do void foo (Stack *s) { while(!s rightarrow isEmpty()) { cout Solution This function is written to call a stack which is a recursive data structure. A stack is basically a collection of objects which is based on LIFO(Last In First Out) where the element that is inserted at the last will be deleted first from the stack. To insert an element we use PUSH in a stack and to delete we use POP. TOP represents the top element in the stack. In this program, function foo calls a stack s and in the while loop there is a condition (!s- >isEmpty()) which checks whether the stack is empty or not. If the stack is not empty then the program prints the top element of the stack (cout<top()) and then s->pop(); means that after printing the top element pop opertaion is being called which deletes the top most element of the stack. So this program will delete all the elements of the stack until the stack is empty. Example- the stack has elements inserted as 10,9,8,7. So the program will print 10,9,8,7 and will delete them one by one. First 10 will be deleted then 9 and so on as stack follows a LIFO structure.