Pure Programmer
Blue Matrix


Cluster Map

Abstract Data Types (ADT)

L1

This page is under construction. Please come back later.

ADTStack.py
#!/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))

Output
$ python3 ADTStack.py 10 10 9 8 7 6 5 4 3 2 1 Can't pop on empty stack!
HelloWorld.py
#!/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!
HelloWorld.py
#!/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!
python

Questions

Projects

More ★'s indicate higher difficulty level.

References