DS140223 #Class Stack

class stack:
def init(self):
self.data = [9,8,7,6,5]
def pop(self,index):
return self.data.pop(index)
def display(self):
print(self.data)
def peek(self):
return self.data[-1]

s = stack()
s.display()
print(s.pop(2))
s.display()
print(s.peek())

5 Likes

class stack():
def init(self) :
self.data=[]
def push(self,element):
self.data.append(element)
def Pop(self,index):
print(self.data.pop(index))
def peek(self):
print(self.data[-1])
def display(self):
print(self.data)
obj=stack()
obj.push(5)
obj.push(6)
obj.push(7)
obj.push(8)
obj.push(9)
obj.Pop((-3))
obj.peek()
obj.display()

5 Likes

Class Stack:
def init(self):
self.data=[]
def push(self,elements):
return self.data.append(elements)
def pop(self,index):
# if not self.isEmpty():
return self.data.pop(index)
# else:
# print(“Stack is empty!!!”)
# def ipopsEmpty(self):
# return self.data==0
# def display(self):
# print(self.data)
def pick(self):
return self.data[-1]

stack=Stack()
stack.push(9)
stack.push(8)
stack.push(7)
stack.push(6)
stack.push(5)

print(stack.pop(1))
stack.pick

4 Likes

class stack:
def init (self):
self.data =[]
def push(self,elements):
self.data.append(elements)
return self.data
def pop(self, index):
self.data.pop(index)
return self.data.pop(index)
def peek(self):
print(self.data[-1])
def display(self):
print(self.data)

c = stack()
c.push(5)
c.push(6)
c.push(7)
c.push(8)
c.push(9)
c.display()
c.pop(3)
c.display()
c.peek()

1 Like

class stack:
def init (self):
self.data =[]
def push(self,elements):
a = list(map(int, elements))
print(a)
self.data = [x for x in a]
def pop(self, index):
self.data.pop(index)
return self.data.pop(index)
def peek(self):
print(self.data[-1])
def display(self):
print(self.data)
s = input(“Number of elements to be added”).split(‘,’)
c =stack()
c.push(s)
c.display()
c.pop(3)
c.display()
c.peek()

2 Likes

Great work everyone!!! @surajmadankar3434 @sindhiyadevit @vaishu.swap10112016 @vishalpatidar71149 :heart_eyes: :heart_eyes: :heart_eyes: :heart_eyes: :heart_eyes:

2 Likes