![]() ![]() Deleting elements from the stack : We can delete elements from the stack as shown below : st.pop( ) NOTE : We can add element only at the end of the list as we are implementing list as stack.ģ. Here element ‘5’ is added into a stack named ‘st’ Adding an element to a Stack : We can add element in a stack by using append( ) function as shown below st.append(5) NOTE : Working with stack is similar to working with list (we can add element by append( ), we can remove element by pop( ) and we can display element by using index value)Ģ. St = or st = list( ) #Here st is an empty stack Creating an Empty Stack : An empty stack can be created by using the following code.How to traverse or displaying elements of stack?. ![]() ![]() How to delete / remove elements from the stack.Basic operations that we should know are : The implementation of stack using list is a simple process as there are inbuilt function which we used during working with stack. In the form of List the above stack will be represented as shown below Class 12 Computer Science Data Structure in Python Handout Working with Stack using List: Removal of elements from the top of the Stack is called POP. Examples of stack are pile of books, pile of plates or stack of carom coins. LIFO means the elements which are added in the last would be the first one to remove. A stack is known as LIFO (Last – In, First – Out) data structure in python. In this handout we will learn that how List can be implemented as STACK & QUEUES STACK :Ī stack is a linear data structure in python in which addition and deletion of elements can be done at one end only. There are four data structure in python : In other words we can say that data structure is a way of storing, organizing and fetching data in computer. Practical Implementation of queue using listĪ data structure in python can be defined as a structure which can holds related data.Practical Implementation of stack using list.Class 12 Computer Science Data Structure in Python Handout ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |