SlideShare a Scribd company logo
1 of 26
Part-B1   Stacks
Abstract Data Types (ADTs) ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
The Stack ADT (§4.2) ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Stack Interface in Java ,[object Object],[object Object],public interface   Stack   { public  int  size() ; public  boolean  isEmpty() ; public  Object  top() throws   EmptyStackException ; public void   push(Object o) ; public  Object  pop()   throws   EmptyStackException ; }
Exceptions ,[object Object],[object Object],[object Object],[object Object]
Applications of Stacks ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Array-based Stack  (Implementation)   ,[object Object],[object Object],[object Object],S 0 1 2 t … Algorithm   size () return   t  +   1 Algorithm   pop () if   isEmpty ()   then throw  EmptyStackException   else  t      t      1 return   S [ t  +   1]
Array-based Stack (cont.) ,[object Object],[object Object],[object Object],[object Object],Algorithm   push ( o ) if   t   =   S.length      1   then throw  FullStackException   else  t      t  +   1 S [ t ]     o S 0 1 2 t …
Array-based Stack  (Cont.)  ,[object Object],[object Object],S 0 1 2 t … Algorithm   isEmpty() if   t<0   then   return   true else   return   false Algorithm   top () if   isEmpty ()   then throw  EmptyStackException   return   S [ t  ]
Performance and Limitations for array-based Stack ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Array-based Stack in Java public class   ArrayStack  implements  Stack { // holds the stack elements   private  Object S[ ]; // index to top element private  int top = -1; // constructor public   ArrayStack(int capacity)   {   S = new Object[capacity]);   }
Array-based Stack in Java public  Object  pop()   throws   EmptyStackException { if  isEmpty() throw new   EmptyStackException (“ Empty stack: cannot pop ”); Object temp = S[top]; // facilitates garbage collection   S[top] =   null ; top = top – 1; return   temp;   } public  int  size()   { return  (top + 1);
Array-based Stack in Java public boolean isEmpty() { return (top < 0); } public void push(Object obj) throws FullStackException { if (size() == capacity) throw new FullStackException(&quot;Stack overflow.&quot;); S[++top] = obj; } public Object top() throws EmptyStackException { if (isEmpty()) throw new EmptyStackException(&quot;Stack is empty.&quot;); return S[top]; }
Parentheses Matching ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Parentheses Matching Algorithm ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Parentheses Matching Example 1 ,[object Object],([ Push  [  [ 5 ( Pop  ( Test if ( and X[i] match?  YES ) 4 (( Push ( ( 3 ( Push ( ( 2 Pop  (  Test if  ( and X[i] match?  YES ) 1 ( Push ( ( 0 Output Stack Operation X[i] i
Parentheses Matching Example 1 ,[object Object],Pop ( Test if ( and X[i]  match?  YES ) 9 TRUE Test if  stack is Empty?  YES ( Pop  [ Test if  [ and X[i] match?  YES ] 8 ([ Pop  ( Test if  ( and X[i] match?  YES ) 7 ([( Push ( ( 6 Output Stack Operation X[i] i
Parentheses Matching Example 2 ,[object Object],FASLE Pop ( Test if ( and X[i] match ?  NO  ] 5 ( Pop  [ Test if [ and X[i] match?  YES ] 4 ([ Push [ [ 3 ( Pop  ( Test if ( and X[i] match?  YES ) 2 (( Push ( ( 1 ( Push ( ( 0 Output Stack Operation X[i] i
Computing Spans (not in book) ,[object Object],[object Object],[object Object],[object Object],X S 1 3 2 1 1 2 5 4 3 6
Quadratic Algorithm Algorithm   spans1 ( X, n ) Input   array  X  of  n  integers Output   array  S  of spans of  X   # S      new array of  n  integers   n for   i      0   to   n     1   do n s     1 n while  s     i      X [ i   s ]      X [ i -s+1 ]   1   2   …   ( n     1)   s      s     1   1   2   …   ( n     1) S [ i ]      s     n return   S    1 X[]= 1,2,3, …, n-1, n. ,[object Object]
Computing Spans with a Stack ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Example:  ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Linear Algorithm Algorithm   spans2 ( X, n )   # S      new array of  n  integers     n A      new empty stack     1 for   i      0   to   n     1   do A.push(i)   n   i=n-1  ;  j=n-1 ;  1 while  (i<=0)  do  while   (  A . isEmpty ()     X [ A.top ()]      X [ j ]  )   do   n   j      A.pop ()   n   if  A . isEmpty ()   then       n S [ i ]      i     1   1   else   S [ i ]      i    j +1  n i=j-1;   n return   S      1 ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Summary of Stack  ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Week 3: Tutorial Arrangement ,[object Object],City Uni. Lift 18 Tunnel connecting city U and Festival Walk
Remarks ,[object Object],[object Object],[object Object],[object Object],[object Object]

More Related Content

What's hot

Lecture 02: Preliminaries of Data structure
Lecture 02: Preliminaries of Data structureLecture 02: Preliminaries of Data structure
Lecture 02: Preliminaries of Data structureNurjahan Nipa
 
Data structure lecture7
Data structure lecture7Data structure lecture7
Data structure lecture7Kumar
 
Heaps & Adaptable priority Queues
Heaps & Adaptable priority QueuesHeaps & Adaptable priority Queues
Heaps & Adaptable priority QueuesPriyanka Rana
 
Queues presentation
Queues presentationQueues presentation
Queues presentationToseef Hasan
 
Asymptotic notations(Big O, Omega, Theta )
Asymptotic notations(Big O, Omega, Theta )Asymptotic notations(Big O, Omega, Theta )
Asymptotic notations(Big O, Omega, Theta )swapnac12
 
Conctructing Polytopes via a Vertex Oracle
Conctructing Polytopes via a Vertex OracleConctructing Polytopes via a Vertex Oracle
Conctructing Polytopes via a Vertex OracleVissarion Fisikopoulos
 
lecture 10
lecture 10lecture 10
lecture 10sajinsc
 
Introduction to Machine Learning
Introduction to Machine LearningIntroduction to Machine Learning
Introduction to Machine LearningBig_Data_Ukraine
 
The Functional Programming Triad of fold, scan and iterate
The Functional Programming Triad of fold, scan and iterateThe Functional Programming Triad of fold, scan and iterate
The Functional Programming Triad of fold, scan and iteratePhilip Schwarz
 
Algorithm analysis basics - Seven Functions/Big-Oh/Omega/Theta
Algorithm analysis basics - Seven Functions/Big-Oh/Omega/ThetaAlgorithm analysis basics - Seven Functions/Big-Oh/Omega/Theta
Algorithm analysis basics - Seven Functions/Big-Oh/Omega/ThetaPriyanka Rana
 
Priority queues and heap sorting
Priority queues and heap sortingPriority queues and heap sorting
Priority queues and heap sortingheshekik
 

What's hot (20)

Lecture 02: Preliminaries of Data structure
Lecture 02: Preliminaries of Data structureLecture 02: Preliminaries of Data structure
Lecture 02: Preliminaries of Data structure
 
Queue
QueueQueue
Queue
 
Data structure lecture7
Data structure lecture7Data structure lecture7
Data structure lecture7
 
Best,worst,average case .17581556 045
Best,worst,average case .17581556 045Best,worst,average case .17581556 045
Best,worst,average case .17581556 045
 
Heaps & Adaptable priority Queues
Heaps & Adaptable priority QueuesHeaps & Adaptable priority Queues
Heaps & Adaptable priority Queues
 
Queues presentation
Queues presentationQueues presentation
Queues presentation
 
E10
E10E10
E10
 
Data Structure (Queue)
Data Structure (Queue)Data Structure (Queue)
Data Structure (Queue)
 
Asymptotic notations(Big O, Omega, Theta )
Asymptotic notations(Big O, Omega, Theta )Asymptotic notations(Big O, Omega, Theta )
Asymptotic notations(Big O, Omega, Theta )
 
Priority queues
Priority queuesPriority queues
Priority queues
 
Conctructing Polytopes via a Vertex Oracle
Conctructing Polytopes via a Vertex OracleConctructing Polytopes via a Vertex Oracle
Conctructing Polytopes via a Vertex Oracle
 
lecture 10
lecture 10lecture 10
lecture 10
 
Circular queue
Circular queueCircular queue
Circular queue
 
Introduction to Machine Learning
Introduction to Machine LearningIntroduction to Machine Learning
Introduction to Machine Learning
 
The Functional Programming Triad of fold, scan and iterate
The Functional Programming Triad of fold, scan and iterateThe Functional Programming Triad of fold, scan and iterate
The Functional Programming Triad of fold, scan and iterate
 
Maps&hash tables
Maps&hash tablesMaps&hash tables
Maps&hash tables
 
Algorithms DM
Algorithms DMAlgorithms DM
Algorithms DM
 
Algorithm analysis basics - Seven Functions/Big-Oh/Omega/Theta
Algorithm analysis basics - Seven Functions/Big-Oh/Omega/ThetaAlgorithm analysis basics - Seven Functions/Big-Oh/Omega/Theta
Algorithm analysis basics - Seven Functions/Big-Oh/Omega/Theta
 
Shunting yard
Shunting yardShunting yard
Shunting yard
 
Priority queues and heap sorting
Priority queues and heap sortingPriority queues and heap sorting
Priority queues and heap sorting
 

Viewers also liked

The Hackathon Zoo
The Hackathon ZooThe Hackathon Zoo
The Hackathon ZooKevin Lewis
 
Con8896 securely enabling mobile access for business transformation - final
Con8896  securely enabling mobile access for business transformation - finalCon8896  securely enabling mobile access for business transformation - final
Con8896 securely enabling mobile access for business transformation - finalOracleIDM
 
То, что вы хотели знать о HandlerSocket, но не смогли нагуглить
 То, что вы хотели знать о HandlerSocket, но не смогли нагуглить То, что вы хотели знать о HandlerSocket, но не смогли нагуглить
То, что вы хотели знать о HandlerSocket, но не смогли нагуглитьSergey Xek
 
Educ 2190 mathematics stage 5 – year 10 – statistics
Educ 2190   mathematics stage 5 – year 10 – statisticsEduc 2190   mathematics stage 5 – year 10 – statistics
Educ 2190 mathematics stage 5 – year 10 – statisticsMatthew Lovegrove
 
Egoera: La Economía de Bizkaia - Junio 2016 - nº23
Egoera: La Economía de Bizkaia - Junio 2016 - nº23Egoera: La Economía de Bizkaia - Junio 2016 - nº23
Egoera: La Economía de Bizkaia - Junio 2016 - nº23Cámara de Comercio de Bilbao
 
Social challenges exposition
Social challenges expositionSocial challenges exposition
Social challenges expositionDilsy Sandoval
 
Маркетинговая программа "Быстрого роста 3+3"
Маркетинговая программа "Быстрого роста 3+3"Маркетинговая программа "Быстрого роста 3+3"
Маркетинговая программа "Быстрого роста 3+3"Елена Шальнова
 
58 c8921e e1fe-408b-bb39ff295ee367b9
58 c8921e e1fe-408b-bb39ff295ee367b958 c8921e e1fe-408b-bb39ff295ee367b9
58 c8921e e1fe-408b-bb39ff295ee367b9Carlos Carvalho
 
Wellbeing 2011 Fact Sheet English
Wellbeing 2011  Fact  Sheet  EnglishWellbeing 2011  Fact  Sheet  English
Wellbeing 2011 Fact Sheet EnglishCheryl Deguara
 
McCrindle Research Pty Ltd
McCrindle Research Pty LtdMcCrindle Research Pty Ltd
McCrindle Research Pty Ltdjohnarthur101
 

Viewers also liked (20)

The Hackathon Zoo
The Hackathon ZooThe Hackathon Zoo
The Hackathon Zoo
 
Con8896 securely enabling mobile access for business transformation - final
Con8896  securely enabling mobile access for business transformation - finalCon8896  securely enabling mobile access for business transformation - final
Con8896 securely enabling mobile access for business transformation - final
 
Notam 15 04
Notam 15 04Notam 15 04
Notam 15 04
 
ขั้นตอนศาสนพิธี
ขั้นตอนศาสนพิธีขั้นตอนศาสนพิธี
ขั้นตอนศาสนพิธี
 
То, что вы хотели знать о HandlerSocket, но не смогли нагуглить
 То, что вы хотели знать о HandlerSocket, но не смогли нагуглить То, что вы хотели знать о HandlerSocket, но не смогли нагуглить
То, что вы хотели знать о HandlerSocket, но не смогли нагуглить
 
PNY Power Bank Series for Smart Devices
PNY Power Bank Series for Smart DevicesPNY Power Bank Series for Smart Devices
PNY Power Bank Series for Smart Devices
 
Educ 2190 mathematics stage 5 – year 10 – statistics
Educ 2190   mathematics stage 5 – year 10 – statisticsEduc 2190   mathematics stage 5 – year 10 – statistics
Educ 2190 mathematics stage 5 – year 10 – statistics
 
Solarpower by holly
Solarpower by hollySolarpower by holly
Solarpower by holly
 
Egoera: La Economía de Bizkaia - Junio 2016 - nº23
Egoera: La Economía de Bizkaia - Junio 2016 - nº23Egoera: La Economía de Bizkaia - Junio 2016 - nº23
Egoera: La Economía de Bizkaia - Junio 2016 - nº23
 
Social challenges exposition
Social challenges expositionSocial challenges exposition
Social challenges exposition
 
Back to the future of hr@ams
Back to the future of hr@amsBack to the future of hr@ams
Back to the future of hr@ams
 
Sports in england
Sports in englandSports in england
Sports in england
 
Маркетинговая программа "Быстрого роста 3+3"
Маркетинговая программа "Быстрого роста 3+3"Маркетинговая программа "Быстрого роста 3+3"
Маркетинговая программа "Быстрого роста 3+3"
 
Quiet hotelroom
Quiet hotelroomQuiet hotelroom
Quiet hotelroom
 
58 c8921e e1fe-408b-bb39ff295ee367b9
58 c8921e e1fe-408b-bb39ff295ee367b958 c8921e e1fe-408b-bb39ff295ee367b9
58 c8921e e1fe-408b-bb39ff295ee367b9
 
Begin scripting
Begin scriptingBegin scripting
Begin scripting
 
Preghiera a San Michele Arcangelo E-book
Preghiera a  San Michele Arcangelo E-bookPreghiera a  San Michele Arcangelo E-book
Preghiera a San Michele Arcangelo E-book
 
Wellbeing 2011 Fact Sheet English
Wellbeing 2011  Fact  Sheet  EnglishWellbeing 2011  Fact  Sheet  English
Wellbeing 2011 Fact Sheet English
 
McCrindle Research Pty Ltd
McCrindle Research Pty LtdMcCrindle Research Pty Ltd
McCrindle Research Pty Ltd
 
IHC Ace PPT
IHC Ace PPTIHC Ace PPT
IHC Ace PPT
 

Similar to Lecture2

Similar to Lecture2 (20)

Lec2
Lec2Lec2
Lec2
 
stack (1).pptx
stack (1).pptxstack (1).pptx
stack (1).pptx
 
Lec2
Lec2Lec2
Lec2
 
03 stacks and_queues_using_arrays
03 stacks and_queues_using_arrays03 stacks and_queues_using_arrays
03 stacks and_queues_using_arrays
 
Stack linked list
Stack linked listStack linked list
Stack linked list
 
U3.stack queue
U3.stack queueU3.stack queue
U3.stack queue
 
stack presentation
stack presentationstack presentation
stack presentation
 
Stacks queues
Stacks queuesStacks queues
Stacks queues
 
Basic data-structures-v.1.1
Basic data-structures-v.1.1Basic data-structures-v.1.1
Basic data-structures-v.1.1
 
Stack concepts by Divya
Stack concepts by DivyaStack concepts by Divya
Stack concepts by Divya
 
Data structure lab manual
Data structure lab manualData structure lab manual
Data structure lab manual
 
Stack.pptx
Stack.pptxStack.pptx
Stack.pptx
 
Lecture 4 - List, Stack, Queues, Deques.pdf
Lecture 4 - List, Stack, Queues, Deques.pdfLecture 4 - List, Stack, Queues, Deques.pdf
Lecture 4 - List, Stack, Queues, Deques.pdf
 
Stacks
StacksStacks
Stacks
 
01-intro_stacks.ppt
01-intro_stacks.ppt01-intro_stacks.ppt
01-intro_stacks.ppt
 
What is Stack, Its Operations, Queue, Circular Queue, Priority Queue
What is Stack, Its Operations, Queue, Circular Queue, Priority QueueWhat is Stack, Its Operations, Queue, Circular Queue, Priority Queue
What is Stack, Its Operations, Queue, Circular Queue, Priority Queue
 
Data Structure.pptx
Data Structure.pptxData Structure.pptx
Data Structure.pptx
 
Educational slides by venay magen
Educational slides by venay magenEducational slides by venay magen
Educational slides by venay magen
 
Python programming : Arrays
Python programming : ArraysPython programming : Arrays
Python programming : Arrays
 
DS MOD2 (1) (1).pptx
DS MOD2 (1) (1).pptxDS MOD2 (1) (1).pptx
DS MOD2 (1) (1).pptx
 

More from FALLEE31188 (20)

Lecture4
Lecture4Lecture4
Lecture4
 
L16
L16L16
L16
 
L2
L2L2
L2
 
Inheritance
InheritanceInheritance
Inheritance
 
Inheritance
InheritanceInheritance
Inheritance
 
Functions
FunctionsFunctions
Functions
 
Field name
Field nameField name
Field name
 
Encapsulation
EncapsulationEncapsulation
Encapsulation
 
Cpp tutorial
Cpp tutorialCpp tutorial
Cpp tutorial
 
Cis068 08
Cis068 08Cis068 08
Cis068 08
 
Chapter14
Chapter14Chapter14
Chapter14
 
Chapt03
Chapt03Chapt03
Chapt03
 
C++lecture9
C++lecture9C++lecture9
C++lecture9
 
C++ polymorphism
C++ polymorphismC++ polymorphism
C++ polymorphism
 
C++ classes tutorials
C++ classes tutorialsC++ classes tutorials
C++ classes tutorials
 
C1320prespost
C1320prespostC1320prespost
C1320prespost
 
Brookshear 06
Brookshear 06Brookshear 06
Brookshear 06
 
Book ppt
Book pptBook ppt
Book ppt
 
Assignment 2
Assignment 2Assignment 2
Assignment 2
 
Assignment
AssignmentAssignment
Assignment
 

Recently uploaded

CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room servicediscovermytutordmt
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajanpragatimahajan3
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docxPoojaSen20
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpinRaunakKeshri1
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
The byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptxThe byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptxShobhayan Kirtania
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Disha Kariya
 

Recently uploaded (20)

CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room service
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajan
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docx
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpin
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
The byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptxThe byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptx
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 

Lecture2

  • 1. Part-B1 Stacks
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11. Array-based Stack in Java public class ArrayStack implements Stack { // holds the stack elements private Object S[ ]; // index to top element private int top = -1; // constructor public ArrayStack(int capacity) { S = new Object[capacity]); }
  • 12. Array-based Stack in Java public Object pop() throws EmptyStackException { if isEmpty() throw new EmptyStackException (“ Empty stack: cannot pop ”); Object temp = S[top]; // facilitates garbage collection S[top] = null ; top = top – 1; return temp; } public int size() { return (top + 1);
  • 13. Array-based Stack in Java public boolean isEmpty() { return (top < 0); } public void push(Object obj) throws FullStackException { if (size() == capacity) throw new FullStackException(&quot;Stack overflow.&quot;); S[++top] = obj; } public Object top() throws EmptyStackException { if (isEmpty()) throw new EmptyStackException(&quot;Stack is empty.&quot;); return S[top]; }
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.