SlideShare a Scribd company logo
Computer Science
Chapter 5: Data-structures:
lists,stack,queue
Data-structures
It a way of organizing and storing data in such a manner so that it can be accessed
and work over it. This can be done efficiently and uses less resources are required. It
define the relationship between the data and the operations over those data. There
are various types of data structures defined that make it easier for the computer
programmer,to concentrate on the main problems rather than getting lost in the
details of data description and access.
Python Data Structure
List
It is a collections of items and each item has its own index value.
Index of first item is 0 and the last item is n-1.Here n is number of items in a list.
Indexing of list
Creating a list
Lists are enclosed in square brackets [ ] and each item is separated by a comma.
e.g.
list1 = [‘English', ‘Hindi', 1997, 2000];
list2 = [11, 22, 33, 44, 55 ];
list3 = ["a", "b", "c", "d"];
Data-structures
Access Items From A List
List items can be accessed using its index position.
output
e.g.
list =[3,5,9]
print(list[0])
print(list[1])
print(list[2])
print('Negativeindexing')
print(list[-1])
print(list[-2])
print(list[-3])
3
5
9
Negative indexing
9
5
3
Data-structures
Iterating Through A List
List elements can be accessed using looping statement.
e.g.
list =[3,5,9]
for i in range(0,len(list)):
print(list[i])
Output
3
5
9
Visit : python.mykvs.in for regular updates
Data-structures
Important methods and functions of List
Function
list.append()
list.extend()
list.insert()
list.remove()
del list[index]
list.clear()
list.pop()
list.index()
list.sort()
list.reverse()
len(list)
max(list)
min(list)
list(seq)
Description
Add an Item at end of a list
Add multiple Items at end of a list
insert an Item at a defined index
remove an Item from a list
Delete an Item from a list
empty all the list
Remove an Item at a defined index
Return index of first matched item
Sort the items of a list in ascending or descending order
Reverse the items of a list
Return total length of the list.
Return item with maximum value in the list.
Return item with min value in the list.
Converts a tuple, string, set, dictionary into
list.
Data-structures
Stack:
A stack is a linear data structure in which all the
insertion and deletion of data / values are done at one end only.





It is type of linear data structure.
It follows LIFO(Last In First Out)
property.
Insertion / Deletion in stack can
only be done from top.
Insertion in stack is also known as
a PUSH operation.
Deletion from stack is also known
as POP operation in stack.
Data-structures
Applications of Stack:
•
•
•
•
•
•
•
Expression Evaluation: It is used to evaluate prefix, postfix and infix
expressions.
Expression Conversion: It can be used to convert one form of
expression(prefix,postfix or infix) to one another.
Syntax Parsing: Many compilers use a stack for parsing the
syntax of
expressions.
Backtracking: It can be used for back traversal of steps in a
problem solution.
Parenthesis Checking: Stack is used to check the proper opening
and closing of parenthesis.
String Reversal: It can be used to reverse a string.
Function Call: Stack is used to keep information about the active
functions or subroutines.
Data-structures
Using List as Stack in Python:
The concept of Stack implementation is easy in Python ,
because it support inbuilt functions (append() and pop())
for stack implementation.By Using these functions make
the code short and simple for stack implementation.
To add an item to the top of the list, i.e., to push an item,
we use append() function and to pop out an element we
use pop() function. These functions work quiet efficiently
and fast in end operations.
Data-structures
Stack e.g. program:
stack = [5, 9, 3]
stack.append(7)
stack.append(11)
print(stack)
print(stack.pop()
) print(stack)
print(stack.pop()
) print(stack)
OUTPUT
[5, 9, 3, 7, 11]
11
[5, 9, 3, 7]
7
[5, 9, 3]
Data-structures
class Stack:
def init
(self):
self.items = []
def is_empty(self):
return self.items == [] def
push(self, data):
self.items.append(data) def
pop(self):
return self.items.pop()
s = Stack() while
True:
print('Press 1 for push')
print('Press 2 for pop')
print('Press 3 for quit')
do = int(input('What would
you like to do'))
Stack interactive
program:
Data-structures
if do == 1:
n=int(input("enter a number to push")) s.push(n)
elif do == 2:
if s.is_empty(): print('Stack is empty.')
else:
print('Popped value: ', s.pop()) elif
operation ==
3:
Ad

More Related Content

Similar to Data -structures for class 12 , easy ppt (20)

DS Complete notes for Computer science and Engineering
DS Complete notes for Computer science and EngineeringDS Complete notes for Computer science and Engineering
DS Complete notes for Computer science and Engineering
RAJASEKHARV8
 
data structures with algorithms vtu 2023 notes.pptx
data structures with algorithms  vtu 2023 notes.pptxdata structures with algorithms  vtu 2023 notes.pptx
data structures with algorithms vtu 2023 notes.pptx
hemanthkumar40680
 
1597380885789.ppt
1597380885789.ppt1597380885789.ppt
1597380885789.ppt
PraveenKumar977108
 
DATA STRUCTURE AND ALGORITJM POWERPOINT.ppt
DATA STRUCTURE AND ALGORITJM POWERPOINT.pptDATA STRUCTURE AND ALGORITJM POWERPOINT.ppt
DATA STRUCTURE AND ALGORITJM POWERPOINT.ppt
yarotos643
 
1 list datastructures
1 list datastructures1 list datastructures
1 list datastructures
Nguync91368
 
Introduction to Data structures and Trees.ppt
Introduction to Data structures and Trees.pptIntroduction to Data structures and Trees.ppt
Introduction to Data structures and Trees.ppt
Vivekananda Gn
 
UNITIII LDS.pdf
UNITIII LDS.pdfUNITIII LDS.pdf
UNITIII LDS.pdf
meenamadhuvandhi2
 
Chapter 5 ds
Chapter 5 dsChapter 5 ds
Chapter 5 ds
Hanif Durad
 
Ch-8.pdf
Ch-8.pdfCh-8.pdf
Ch-8.pdf
R.K.College of engg & Tech
 
11 Introduction to lists.pptx
11 Introduction to lists.pptx11 Introduction to lists.pptx
11 Introduction to lists.pptx
ssuser8e50d8
 
Datastructures and algorithms prepared by M.V.Brehmanada Reddy
Datastructures and algorithms prepared by M.V.Brehmanada ReddyDatastructures and algorithms prepared by M.V.Brehmanada Reddy
Datastructures and algorithms prepared by M.V.Brehmanada Reddy
Malikireddy Bramhananda Reddy
 
data structure details of types and .ppt
data structure details of types and .pptdata structure details of types and .ppt
data structure details of types and .ppt
poonamsngr
 
STACK, LINKED LIST ,AND QUEUE
STACK, LINKED LIST ,AND QUEUESTACK, LINKED LIST ,AND QUEUE
STACK, LINKED LIST ,AND QUEUE
Dev Chauhan
 
PROBLEM SOLVING AND PYTHON PROGRAMMING PPT
PROBLEM SOLVING AND PYTHON PROGRAMMING PPTPROBLEM SOLVING AND PYTHON PROGRAMMING PPT
PROBLEM SOLVING AND PYTHON PROGRAMMING PPT
MulliMary
 
Basic data-structures-v.1.1
Basic data-structures-v.1.1Basic data-structures-v.1.1
Basic data-structures-v.1.1
BG Java EE Course
 
16 Linear data structures
16 Linear data structures16 Linear data structures
16 Linear data structures
maznabili
 
DATA STRUCTURES A BRIEF OVERVIEW OF DATA
DATA STRUCTURES A BRIEF OVERVIEW OF DATADATA STRUCTURES A BRIEF OVERVIEW OF DATA
DATA STRUCTURES A BRIEF OVERVIEW OF DATA
LearnItAllAcademy
 
different types of data structures using c.ppt
different types of data structures using c.pptdifferent types of data structures using c.ppt
different types of data structures using c.ppt
RaviKumarChavali1
 
DS_INTROduction dhjm,asjkfnsflkwefskdmcsdmckds
DS_INTROduction dhjm,asjkfnsflkwefskdmcsdmckdsDS_INTROduction dhjm,asjkfnsflkwefskdmcsdmckds
DS_INTROduction dhjm,asjkfnsflkwefskdmcsdmckds
aayushkumarsinghec22
 
PM.ppt DATA STRUCTURE USING C WITH EXAMPLE PROGRAMES
PM.ppt DATA STRUCTURE USING C    WITH EXAMPLE PROGRAMESPM.ppt DATA STRUCTURE USING C    WITH EXAMPLE PROGRAMES
PM.ppt DATA STRUCTURE USING C WITH EXAMPLE PROGRAMES
NagarathnaRajur2
 
DS Complete notes for Computer science and Engineering
DS Complete notes for Computer science and EngineeringDS Complete notes for Computer science and Engineering
DS Complete notes for Computer science and Engineering
RAJASEKHARV8
 
data structures with algorithms vtu 2023 notes.pptx
data structures with algorithms  vtu 2023 notes.pptxdata structures with algorithms  vtu 2023 notes.pptx
data structures with algorithms vtu 2023 notes.pptx
hemanthkumar40680
 
DATA STRUCTURE AND ALGORITJM POWERPOINT.ppt
DATA STRUCTURE AND ALGORITJM POWERPOINT.pptDATA STRUCTURE AND ALGORITJM POWERPOINT.ppt
DATA STRUCTURE AND ALGORITJM POWERPOINT.ppt
yarotos643
 
1 list datastructures
1 list datastructures1 list datastructures
1 list datastructures
Nguync91368
 
Introduction to Data structures and Trees.ppt
Introduction to Data structures and Trees.pptIntroduction to Data structures and Trees.ppt
Introduction to Data structures and Trees.ppt
Vivekananda Gn
 
11 Introduction to lists.pptx
11 Introduction to lists.pptx11 Introduction to lists.pptx
11 Introduction to lists.pptx
ssuser8e50d8
 
Datastructures and algorithms prepared by M.V.Brehmanada Reddy
Datastructures and algorithms prepared by M.V.Brehmanada ReddyDatastructures and algorithms prepared by M.V.Brehmanada Reddy
Datastructures and algorithms prepared by M.V.Brehmanada Reddy
Malikireddy Bramhananda Reddy
 
data structure details of types and .ppt
data structure details of types and .pptdata structure details of types and .ppt
data structure details of types and .ppt
poonamsngr
 
STACK, LINKED LIST ,AND QUEUE
STACK, LINKED LIST ,AND QUEUESTACK, LINKED LIST ,AND QUEUE
STACK, LINKED LIST ,AND QUEUE
Dev Chauhan
 
PROBLEM SOLVING AND PYTHON PROGRAMMING PPT
PROBLEM SOLVING AND PYTHON PROGRAMMING PPTPROBLEM SOLVING AND PYTHON PROGRAMMING PPT
PROBLEM SOLVING AND PYTHON PROGRAMMING PPT
MulliMary
 
16 Linear data structures
16 Linear data structures16 Linear data structures
16 Linear data structures
maznabili
 
DATA STRUCTURES A BRIEF OVERVIEW OF DATA
DATA STRUCTURES A BRIEF OVERVIEW OF DATADATA STRUCTURES A BRIEF OVERVIEW OF DATA
DATA STRUCTURES A BRIEF OVERVIEW OF DATA
LearnItAllAcademy
 
different types of data structures using c.ppt
different types of data structures using c.pptdifferent types of data structures using c.ppt
different types of data structures using c.ppt
RaviKumarChavali1
 
DS_INTROduction dhjm,asjkfnsflkwefskdmcsdmckds
DS_INTROduction dhjm,asjkfnsflkwefskdmcsdmckdsDS_INTROduction dhjm,asjkfnsflkwefskdmcsdmckds
DS_INTROduction dhjm,asjkfnsflkwefskdmcsdmckds
aayushkumarsinghec22
 
PM.ppt DATA STRUCTURE USING C WITH EXAMPLE PROGRAMES
PM.ppt DATA STRUCTURE USING C    WITH EXAMPLE PROGRAMESPM.ppt DATA STRUCTURE USING C    WITH EXAMPLE PROGRAMES
PM.ppt DATA STRUCTURE USING C WITH EXAMPLE PROGRAMES
NagarathnaRajur2
 

Recently uploaded (20)

Programs as Values - Write code and don't get lost
Programs as Values - Write code and don't get lostPrograms as Values - Write code and don't get lost
Programs as Values - Write code and don't get lost
Pierangelo Cecchetto
 
The-Future-is-Hybrid-Exploring-Azure’s-Role-in-Multi-Cloud-Strategies.pptx
The-Future-is-Hybrid-Exploring-Azure’s-Role-in-Multi-Cloud-Strategies.pptxThe-Future-is-Hybrid-Exploring-Azure’s-Role-in-Multi-Cloud-Strategies.pptx
The-Future-is-Hybrid-Exploring-Azure’s-Role-in-Multi-Cloud-Strategies.pptx
james brownuae
 
wAIred_LearnWithOutAI_JCON_14052025.pptx
wAIred_LearnWithOutAI_JCON_14052025.pptxwAIred_LearnWithOutAI_JCON_14052025.pptx
wAIred_LearnWithOutAI_JCON_14052025.pptx
SimonedeGijt
 
Buy vs. Build: Unlocking the right path for your training tech
Buy vs. Build: Unlocking the right path for your training techBuy vs. Build: Unlocking the right path for your training tech
Buy vs. Build: Unlocking the right path for your training tech
Rustici Software
 
Medical Device Cybersecurity Threat & Risk Scoring
Medical Device Cybersecurity Threat & Risk ScoringMedical Device Cybersecurity Threat & Risk Scoring
Medical Device Cybersecurity Threat & Risk Scoring
ICS
 
Wilcom Embroidery Studio Crack 2025 For Windows
Wilcom Embroidery Studio Crack 2025 For WindowsWilcom Embroidery Studio Crack 2025 For Windows
Wilcom Embroidery Studio Crack 2025 For Windows
Google
 
Artificial hand using embedded system.pptx
Artificial hand using embedded system.pptxArtificial hand using embedded system.pptx
Artificial hand using embedded system.pptx
bhoomigowda12345
 
The Elixir Developer - All Things Open
The Elixir Developer - All Things OpenThe Elixir Developer - All Things Open
The Elixir Developer - All Things Open
Carlo Gilmar Padilla Santana
 
NYC ACE 08-May-2025-Combined Presentation.pdf
NYC ACE 08-May-2025-Combined Presentation.pdfNYC ACE 08-May-2025-Combined Presentation.pdf
NYC ACE 08-May-2025-Combined Presentation.pdf
AUGNYC
 
Adobe InDesign Crack FREE Download 2025 link
Adobe InDesign Crack FREE Download 2025 linkAdobe InDesign Crack FREE Download 2025 link
Adobe InDesign Crack FREE Download 2025 link
mahmadzubair09
 
[gbgcpp] Let's get comfortable with concepts
[gbgcpp] Let's get comfortable with concepts[gbgcpp] Let's get comfortable with concepts
[gbgcpp] Let's get comfortable with concepts
Dimitrios Platis
 
Reinventing Microservices Efficiency and Innovation with Single-Runtime
Reinventing Microservices Efficiency and Innovation with Single-RuntimeReinventing Microservices Efficiency and Innovation with Single-Runtime
Reinventing Microservices Efficiency and Innovation with Single-Runtime
Natan Silnitsky
 
AEM User Group DACH - 2025 Inaugural Meeting
AEM User Group DACH - 2025 Inaugural MeetingAEM User Group DACH - 2025 Inaugural Meeting
AEM User Group DACH - 2025 Inaugural Meeting
jennaf3
 
Why Tapitag Ranks Among the Best Digital Business Card Providers
Why Tapitag Ranks Among the Best Digital Business Card ProvidersWhy Tapitag Ranks Among the Best Digital Business Card Providers
Why Tapitag Ranks Among the Best Digital Business Card Providers
Tapitag
 
How to Install and Activate ListGrabber Plugin
How to Install and Activate ListGrabber PluginHow to Install and Activate ListGrabber Plugin
How to Install and Activate ListGrabber Plugin
eGrabber
 
Digital Twins Software Service in Belfast
Digital Twins Software Service in BelfastDigital Twins Software Service in Belfast
Digital Twins Software Service in Belfast
julia smits
 
Surviving a Downturn Making Smarter Portfolio Decisions with OnePlan - Webina...
Surviving a Downturn Making Smarter Portfolio Decisions with OnePlan - Webina...Surviving a Downturn Making Smarter Portfolio Decisions with OnePlan - Webina...
Surviving a Downturn Making Smarter Portfolio Decisions with OnePlan - Webina...
OnePlan Solutions
 
Robotic Process Automation (RPA) Software Development Services.pptx
Robotic Process Automation (RPA) Software Development Services.pptxRobotic Process Automation (RPA) Software Development Services.pptx
Robotic Process Automation (RPA) Software Development Services.pptx
julia smits
 
How to Troubleshoot 9 Types of OutOfMemoryError
How to Troubleshoot 9 Types of OutOfMemoryErrorHow to Troubleshoot 9 Types of OutOfMemoryError
How to Troubleshoot 9 Types of OutOfMemoryError
Tier1 app
 
Serato DJ Pro Crack Latest Version 2025??
Serato DJ Pro Crack Latest Version 2025??Serato DJ Pro Crack Latest Version 2025??
Serato DJ Pro Crack Latest Version 2025??
Web Designer
 
Programs as Values - Write code and don't get lost
Programs as Values - Write code and don't get lostPrograms as Values - Write code and don't get lost
Programs as Values - Write code and don't get lost
Pierangelo Cecchetto
 
The-Future-is-Hybrid-Exploring-Azure’s-Role-in-Multi-Cloud-Strategies.pptx
The-Future-is-Hybrid-Exploring-Azure’s-Role-in-Multi-Cloud-Strategies.pptxThe-Future-is-Hybrid-Exploring-Azure’s-Role-in-Multi-Cloud-Strategies.pptx
The-Future-is-Hybrid-Exploring-Azure’s-Role-in-Multi-Cloud-Strategies.pptx
james brownuae
 
wAIred_LearnWithOutAI_JCON_14052025.pptx
wAIred_LearnWithOutAI_JCON_14052025.pptxwAIred_LearnWithOutAI_JCON_14052025.pptx
wAIred_LearnWithOutAI_JCON_14052025.pptx
SimonedeGijt
 
Buy vs. Build: Unlocking the right path for your training tech
Buy vs. Build: Unlocking the right path for your training techBuy vs. Build: Unlocking the right path for your training tech
Buy vs. Build: Unlocking the right path for your training tech
Rustici Software
 
Medical Device Cybersecurity Threat & Risk Scoring
Medical Device Cybersecurity Threat & Risk ScoringMedical Device Cybersecurity Threat & Risk Scoring
Medical Device Cybersecurity Threat & Risk Scoring
ICS
 
Wilcom Embroidery Studio Crack 2025 For Windows
Wilcom Embroidery Studio Crack 2025 For WindowsWilcom Embroidery Studio Crack 2025 For Windows
Wilcom Embroidery Studio Crack 2025 For Windows
Google
 
Artificial hand using embedded system.pptx
Artificial hand using embedded system.pptxArtificial hand using embedded system.pptx
Artificial hand using embedded system.pptx
bhoomigowda12345
 
NYC ACE 08-May-2025-Combined Presentation.pdf
NYC ACE 08-May-2025-Combined Presentation.pdfNYC ACE 08-May-2025-Combined Presentation.pdf
NYC ACE 08-May-2025-Combined Presentation.pdf
AUGNYC
 
Adobe InDesign Crack FREE Download 2025 link
Adobe InDesign Crack FREE Download 2025 linkAdobe InDesign Crack FREE Download 2025 link
Adobe InDesign Crack FREE Download 2025 link
mahmadzubair09
 
[gbgcpp] Let's get comfortable with concepts
[gbgcpp] Let's get comfortable with concepts[gbgcpp] Let's get comfortable with concepts
[gbgcpp] Let's get comfortable with concepts
Dimitrios Platis
 
Reinventing Microservices Efficiency and Innovation with Single-Runtime
Reinventing Microservices Efficiency and Innovation with Single-RuntimeReinventing Microservices Efficiency and Innovation with Single-Runtime
Reinventing Microservices Efficiency and Innovation with Single-Runtime
Natan Silnitsky
 
AEM User Group DACH - 2025 Inaugural Meeting
AEM User Group DACH - 2025 Inaugural MeetingAEM User Group DACH - 2025 Inaugural Meeting
AEM User Group DACH - 2025 Inaugural Meeting
jennaf3
 
Why Tapitag Ranks Among the Best Digital Business Card Providers
Why Tapitag Ranks Among the Best Digital Business Card ProvidersWhy Tapitag Ranks Among the Best Digital Business Card Providers
Why Tapitag Ranks Among the Best Digital Business Card Providers
Tapitag
 
How to Install and Activate ListGrabber Plugin
How to Install and Activate ListGrabber PluginHow to Install and Activate ListGrabber Plugin
How to Install and Activate ListGrabber Plugin
eGrabber
 
Digital Twins Software Service in Belfast
Digital Twins Software Service in BelfastDigital Twins Software Service in Belfast
Digital Twins Software Service in Belfast
julia smits
 
Surviving a Downturn Making Smarter Portfolio Decisions with OnePlan - Webina...
Surviving a Downturn Making Smarter Portfolio Decisions with OnePlan - Webina...Surviving a Downturn Making Smarter Portfolio Decisions with OnePlan - Webina...
Surviving a Downturn Making Smarter Portfolio Decisions with OnePlan - Webina...
OnePlan Solutions
 
Robotic Process Automation (RPA) Software Development Services.pptx
Robotic Process Automation (RPA) Software Development Services.pptxRobotic Process Automation (RPA) Software Development Services.pptx
Robotic Process Automation (RPA) Software Development Services.pptx
julia smits
 
How to Troubleshoot 9 Types of OutOfMemoryError
How to Troubleshoot 9 Types of OutOfMemoryErrorHow to Troubleshoot 9 Types of OutOfMemoryError
How to Troubleshoot 9 Types of OutOfMemoryError
Tier1 app
 
Serato DJ Pro Crack Latest Version 2025??
Serato DJ Pro Crack Latest Version 2025??Serato DJ Pro Crack Latest Version 2025??
Serato DJ Pro Crack Latest Version 2025??
Web Designer
 
Ad

Data -structures for class 12 , easy ppt

  • 1. Computer Science Chapter 5: Data-structures: lists,stack,queue
  • 2. Data-structures It a way of organizing and storing data in such a manner so that it can be accessed and work over it. This can be done efficiently and uses less resources are required. It define the relationship between the data and the operations over those data. There are various types of data structures defined that make it easier for the computer programmer,to concentrate on the main problems rather than getting lost in the details of data description and access. Python Data Structure
  • 3. List It is a collections of items and each item has its own index value. Index of first item is 0 and the last item is n-1.Here n is number of items in a list. Indexing of list Creating a list Lists are enclosed in square brackets [ ] and each item is separated by a comma. e.g. list1 = [‘English', ‘Hindi', 1997, 2000]; list2 = [11, 22, 33, 44, 55 ]; list3 = ["a", "b", "c", "d"]; Data-structures
  • 4. Access Items From A List List items can be accessed using its index position. output e.g. list =[3,5,9] print(list[0]) print(list[1]) print(list[2]) print('Negativeindexing') print(list[-1]) print(list[-2]) print(list[-3]) 3 5 9 Negative indexing 9 5 3 Data-structures
  • 5. Iterating Through A List List elements can be accessed using looping statement. e.g. list =[3,5,9] for i in range(0,len(list)): print(list[i]) Output 3 5 9 Visit : python.mykvs.in for regular updates Data-structures
  • 6. Important methods and functions of List Function list.append() list.extend() list.insert() list.remove() del list[index] list.clear() list.pop() list.index() list.sort() list.reverse() len(list) max(list) min(list) list(seq) Description Add an Item at end of a list Add multiple Items at end of a list insert an Item at a defined index remove an Item from a list Delete an Item from a list empty all the list Remove an Item at a defined index Return index of first matched item Sort the items of a list in ascending or descending order Reverse the items of a list Return total length of the list. Return item with maximum value in the list. Return item with min value in the list. Converts a tuple, string, set, dictionary into list. Data-structures
  • 7. Stack: A stack is a linear data structure in which all the insertion and deletion of data / values are done at one end only.      It is type of linear data structure. It follows LIFO(Last In First Out) property. Insertion / Deletion in stack can only be done from top. Insertion in stack is also known as a PUSH operation. Deletion from stack is also known as POP operation in stack. Data-structures
  • 8. Applications of Stack: • • • • • • • Expression Evaluation: It is used to evaluate prefix, postfix and infix expressions. Expression Conversion: It can be used to convert one form of expression(prefix,postfix or infix) to one another. Syntax Parsing: Many compilers use a stack for parsing the syntax of expressions. Backtracking: It can be used for back traversal of steps in a problem solution. Parenthesis Checking: Stack is used to check the proper opening and closing of parenthesis. String Reversal: It can be used to reverse a string. Function Call: Stack is used to keep information about the active functions or subroutines. Data-structures
  • 9. Using List as Stack in Python: The concept of Stack implementation is easy in Python , because it support inbuilt functions (append() and pop()) for stack implementation.By Using these functions make the code short and simple for stack implementation. To add an item to the top of the list, i.e., to push an item, we use append() function and to pop out an element we use pop() function. These functions work quiet efficiently and fast in end operations. Data-structures
  • 10. Stack e.g. program: stack = [5, 9, 3] stack.append(7) stack.append(11) print(stack) print(stack.pop() ) print(stack) print(stack.pop() ) print(stack) OUTPUT [5, 9, 3, 7, 11] 11 [5, 9, 3, 7] 7 [5, 9, 3] Data-structures
  • 11. class Stack: def init (self): self.items = [] def is_empty(self): return self.items == [] def push(self, data): self.items.append(data) def pop(self): return self.items.pop() s = Stack() while True: print('Press 1 for push') print('Press 2 for pop') print('Press 3 for quit') do = int(input('What would you like to do')) Stack interactive program: Data-structures if do == 1: n=int(input("enter a number to push")) s.push(n) elif do == 2: if s.is_empty(): print('Stack is empty.') else: print('Popped value: ', s.pop()) elif operation == 3:
  翻译: