Stack Implementation in Python || Lesson 23 || Python Placements || Learning Monkey ||
#pytho #learningmonke #pythoncodin #placement #pythontutorial #pythoncours #pythonforbeginner #pythonfordatascienc #pythonfullcours #pythonprogrammin #pythonfreecourse
Stack Implementation in Python
In this class, we do Stack Implementation in Python.
Stack
This stack implementation in python will help the reader solve the data structure placement questions.
The reader should implement all the data structures in python. With the help of this stack implementation.
If you are not good at data structures. Please check our data structures course.
The concepts of data structures are essential in improving coding skills.
Let’s refresh the idea of the stack. Then we go for implementation.
Stack is a data structure that follows Last in First out order.
The element that is inserted last should be removed first.
To maintain the stack, we need a variable to point to the top of the stack.
The variable that points to the top of the stack we call stack top.
Initially, The variable stack top will point to -1.
The stack top pointing to -1 means the stack is empty.
If the variable stack top is pointing to the last position in the stack. We say the stack is full.
The display operation on the stack. We have to display elements in the stack from top to bottom.
Analyze the logic of the stack program given below. For better practice.
Program
import numpy as np
class stackdatastructure:
def __init__(self,size):
self.stack=np.ndarray((size,),dtype="i")
self.stacktop=-1
def push(self,element):
if self.stacktop==len(self.stack):
print("stack is full")
else:
self.stacktop+=1
self.stack[self.stacktop]=element
print("element inserted")
def pop(self):
if self.stacktop==-1:
print("stack is empty")
else:
print("element pop is")
print(self.stack[self.stacktop])
self.stacktop-=1
def display(self):
print("elements in the stack are")
for i in range(self.stacktop,-1,-1):
print(self.stack[i])
ob1=stackdatastructure(5)
ob1.push(10)
ob1.push(20)
ob1.display()
ob1.pop()
ob1.display()
In the above program, we defined a stack class.
For implementing the stack, one should have basics on class and object concept in python. Click here.
Operations on the stack are push, pop, and display.
Each operation functionality is defined in a method.
When we define an object to the above class, we send the size of the stack.
With this intuition, we can quickly solve the placement questions.
In the placement questions, they will mention stack class is available.
If the Stack class available, we can use the methods known in the stack.
Link for playlists:
https://www.youtube.com/channel/UCl8x4Pn9Mnh_C1fue-Yndig/playlists
Link for our website: https://learningmonkey.in
Follow us on Facebook @ https://www.facebook.com/learningmonkey
Follow us on Instagram @ https://www.instagram.com/learningmonkey1/
Follow us on Twitter @ https://twitter.com/_learningmonkey
Mail us @ [email protected]
Что делает видео по-настоящему запоминающимся? Наверное, та самая атмосфера, которая заставляет забыть о времени. Когда вы заходите на RUVIDEO, чтобы посмотреть онлайн «Stack Implementation in Python || Lesson 23 || Python Placements || Learning Monkey ||», вы рассчитываете на нечто большее, чем просто загрузку плеера. И мы это понимаем. Контент такого уровня заслуживает того, чтобы его смотрели в HD 1080, без дрожания картинки и бесконечного буферизации.
Честно говоря, Rutube сегодня — это кладезь уникальных находок, которые часто теряются в общем шуме. Мы же вытаскиваем на поверхность самое интересное. Будь то динамичный экшн, глубокий разбор темы от любимого автора или просто уютное видео для настроения — всё это доступно здесь бесплатно и без лишних формальностей. Никаких «заполните анкету, чтобы продолжить». Только вы, ваш экран и качественный поток.
Если вас зацепило это видео, не забудьте взглянуть на похожие материалы в блоке справа. Мы откалибровали наши алгоритмы так, чтобы они подбирали контент не просто «по тегам», а по настроению и смыслу. Ведь в конечном итоге, онлайн-кинотеатр — это не склад файлов, а место, где каждый вечер можно найти свою историю. Приятного вам отдыха на RUVIDEO!
Видео взято из открытых источников Rutube. Если вы правообладатель, обратитесь к первоисточнику.