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

1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17Celine George
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - Englishneillewis46
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsKarakKing
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptxMaritesTamaniVerdade
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxAreebaZafar22
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701bronxfugly43
 
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
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin ClassesCeline George
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxAmanpreet Kaur
 
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 Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17Celine George
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibitjbellavia9
 
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
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...christianmathematics
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfNirmal Dwivedi
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structuredhanjurrannsibayan2
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 

Recently uploaded (20)

1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701
 
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
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
 
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 Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
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
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structure
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
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
 

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.