Abstract Data Types (ADT)

This page is under construction. Please come back later.
#!/usr/bin/env python3;
###############################################################################
# This program demonstrates the Stack ADT
#
# Copyright © 2021 Richard Lesh. All rights reserved.
###############################################################################
import Utils
class IntegerStack :
# Internal representation for the stack is a list
stack = []
def __init__(self) :
self.stack = []
def pop(self) :
if (len(self.stack) == 0) :
raise RuntimeError("Can't pop on empty stack!")
return self.stack.pop()
def push(self, value) :
self.stack.append(value)
def peek(self) :
if (len(self.stack) == 0) :
raise RuntimeError("Can't peek on empty stack!")
return self.stack[len(self.stack) - 1]
# Begin Main
stack = IntegerStack()
for x in range(1, 10 + 1) :
stack.push(x)
try :
print(str(stack.peek()))
for x in range(1, 11 + 1) :
print(str(stack.pop()))
except RuntimeError as ex :
print(str(ex))
except Exception as ex :
print("Unknown Exception!")
Output
$ python3 ADTStack.py
10
10
9
8
7
6
5
4
3
2
1
Can't pop on empty stack!
#!/usr/bin/env python3;
###############################################################################
# Simple first program.
#
# Copyright © 2020 Richard Lesh. All rights reserved.
###############################################################################
# Begin Main
print("Hello, world!")
Output
$ python3 HelloWorld.py
Hello, world!
#!/usr/bin/env python3;
###############################################################################
# Simple first program.
#
# Copyright © 2020 Richard Lesh. All rights reserved.
###############################################################################
# Begin Main
print("Hello, world!")
Output
$ python3 HelloWorld.py
Hello, world!
Questions
Projects
More ★'s indicate higher difficulty level.
References
- [[Python Language Reference]]
- [[Python Standard Library]]
- [[Python at TutorialsPoint]]
Pure Programmer


