SlideShare a Scribd company logo
1 of 1
Download to read offline
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 operation algorithms with example
Stack operation algorithms with exampleStack operation algorithms with example
Stack operation algorithms with exampleNamanKikani
 
Applicationofstack by Ali F.RAshid
Applicationofstack  by Ali F.RAshid Applicationofstack  by Ali F.RAshid
Applicationofstack by Ali F.RAshid ali rashid
 
Application of Stack - Yadraj Meena
Application of Stack - Yadraj MeenaApplication of Stack - Yadraj Meena
Application of Stack - Yadraj MeenaDipayan Sarkar
 
Module 2 ppt.pptx
Module 2 ppt.pptxModule 2 ppt.pptx
Module 2 ppt.pptxSonaPathak4
 
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.pptxShivam Kumar
 
Stacks,queues,linked-list
Stacks,queues,linked-listStacks,queues,linked-list
Stacks,queues,linked-listpinakspatel
 
What is Stack? Application of Stack
What is Stack? Application of StackWhat is Stack? Application of Stack
What is Stack? Application of StackShahzeb Amjad
 
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.pdfkesav24
 
Stacks Data structure.pptx
Stacks Data structure.pptxStacks Data structure.pptx
Stacks Data structure.pptxline24arts
 
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.docxtristans3
 
STACK AND ITS OPERATIONS IN DATA STRUCTURES.pptx
STACK AND ITS OPERATIONS IN DATA STRUCTURES.pptxSTACK AND ITS OPERATIONS IN DATA STRUCTURES.pptx
STACK AND ITS OPERATIONS IN DATA STRUCTURES.pptxKALPANAC20
 
Stack and Queue.pptx university exam preparation
Stack and Queue.pptx university exam preparationStack and Queue.pptx university exam preparation
Stack and Queue.pptx university exam preparationRAtna29
 

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

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
 
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
 
STACK AND ITS OPERATIONS IN DATA STRUCTURES.pptx
STACK AND ITS OPERATIONS IN DATA STRUCTURES.pptxSTACK AND ITS OPERATIONS IN DATA STRUCTURES.pptx
STACK AND ITS OPERATIONS IN DATA STRUCTURES.pptx
 
Stack and Queue.pptx university exam preparation
Stack and Queue.pptx university exam preparationStack and Queue.pptx university exam preparation
Stack and Queue.pptx university exam preparation
 

More from meerobertsonheyde608

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.pdfmeerobertsonheyde608
 
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.pdfmeerobertsonheyde608
 
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.pdfmeerobertsonheyde608
 
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.pdfmeerobertsonheyde608
 
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 .pdfmeerobertsonheyde608
 
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.pdfmeerobertsonheyde608
 
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.pdfmeerobertsonheyde608
 
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.pdfmeerobertsonheyde608
 
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.pdfmeerobertsonheyde608
 
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.pdfmeerobertsonheyde608
 
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 .pdfmeerobertsonheyde608
 
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 .pdfmeerobertsonheyde608
 
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.pdfmeerobertsonheyde608
 
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.pdfmeerobertsonheyde608
 
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.pdfmeerobertsonheyde608
 
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.pdfmeerobertsonheyde608
 
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.pdfmeerobertsonheyde608
 
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.pdfmeerobertsonheyde608
 
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.pdfmeerobertsonheyde608
 
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.pdfmeerobertsonheyde608
 

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

This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.christianmathematics
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsMebane Rash
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structuredhanjurrannsibayan2
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentationcamerronhm
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxJisc
 
How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17Celine George
 
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Pooja Bhuva
 
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSSpellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSAnaAcapella
 
OSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsOSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsSandeep D Chaudhary
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jisc
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxDenish Jangid
 
Basic Intentional Injuries Health Education
Basic Intentional Injuries Health EducationBasic Intentional Injuries Health Education
Basic Intentional Injuries Health EducationNeilDeclaro1
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxDr. Sarita Anand
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...Poonam Aher Patil
 
How to Add a Tool Tip to a Field in Odoo 17
How to Add a Tool Tip to a Field in Odoo 17How to Add a Tool Tip to a Field in Odoo 17
How to Add a Tool Tip to a Field in Odoo 17Celine George
 
latest AZ-104 Exam Questions and Answers
latest AZ-104 Exam Questions and Answerslatest AZ-104 Exam Questions and Answers
latest AZ-104 Exam Questions and Answersdalebeck957
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxmarlenawright1
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Jisc
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxheathfieldcps1
 

Recently uploaded (20)

This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structure
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17
 
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
 
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSSpellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
OSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsOSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & Systems
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
Basic Intentional Injuries Health Education
Basic Intentional Injuries Health EducationBasic Intentional Injuries Health Education
Basic Intentional Injuries Health Education
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptx
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
How to Add a Tool Tip to a Field in Odoo 17
How to Add a Tool Tip to a Field in Odoo 17How to Add a Tool Tip to a Field in Odoo 17
How to Add a Tool Tip to a Field in Odoo 17
 
latest AZ-104 Exam Questions and Answers
latest AZ-104 Exam Questions and Answerslatest AZ-104 Exam Questions and Answers
latest AZ-104 Exam Questions and Answers
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 

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.