Written by students who passed Immediately available after payment Read online or as PDF Wrong document? Swap it for free 4.6 TrustPilot
logo-home
Class notes

IMPLEMENT STACK ADT IN PYTHON

Rating
-
Sold
-
Pages
7
Uploaded on
23-05-2024
Written in
2022/2023

This document outlines the implementation of a Stack Abstract Data Type (ADT) in Python. It provides a clear and concise explanation of the Stack concept, its functionalities, and its creation in Python using code examples.

Institution
Course

Content preview

IMPLEMENT STACK ADT IN PYTHON
(a). STACK IMPLEMENTATION USING LIST

EX No: 1(a)
DATE:

AIM:

To write a python program for stack implementation using listin python.


ALGORITHM:
Step 1 : Start
Step 2 : Push elements into a stack
Step 3 : Pop elements from a stack and issue a warning if it's empty
Step 4 : Get the size of the stack to print it
Step 5 : Stop


PROGRAM:
class Stack:
def __init__(self):
self.stack = list()
def push(self,data):
if data not in self.stack:
self.stack.append(data)
return True
return False
def pop(self):
if len(self.stack)<=0:
return ("Stack Empty!")
return self.stack.pop()

, def size(self):
return len(self.stack)


myStack = Stack()
print(myStack.push(5))
print(myStack.push(6))
print(myStack.push(9))
print(myStack.push(5))
print(myStack.push(3))
print(myStack.size())
print(myStack.pop())
print(myStack.pop())
print(myStack.pop())
print(myStack.pop())
print(myStack.size())
print(myStack.pop())



SAMPLE OUTPUT:


True
True
True
False
True
4
3
9
6

Written for

Institution
Course

Document information

Uploaded on
May 23, 2024
Number of pages
7
Written in
2022/2023
Type
Class notes
Professor(s)
Joseph
Contains
All classes

Subjects

$8.49
Get access to the full document:

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Get to know the seller
Seller avatar
kingaadhav555

Get to know the seller

Seller avatar
kingaadhav555
Follow You need to be logged in order to follow users or courses
Sold
-
Member since
1 year
Number of followers
0
Documents
23
Last sold
-

0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions