An example of a stack in Python 3
Project description
Stack module
An example of a stack in Python 3
Example usage
import stackmodule
from stackmodule import stackTools
from random import randint as rand
stackOptions = {
'pointer': -1,
'size': 5,
'type': int
}
stackHandler = stackTools()
stackHandler.stackOptions = stackOptions
stackHandler.stack = stackHandler.initStack(stackOptions['size'],stackOptions['type'])
print(stackHandler.dump())
stackHandler.push(3)
print(stackHandler.dump())
for i in range (0,rand(0,30)):
try:
n=rand(0,651)
stackHandler.push(n)
print(f'Added {n}')
except stackmodule.StackFull: print("Stack got full")
print(stackHandler.dump())
print(stackHandler.pop())
print(stackHandler.dump())
stackHandler.push(5)
print(stackHandler.dump())
stack = stackHandler.dump()
print("The script exported the stack: "+str(stack))
Module features
Making a stack handler
stackHandler=stackTools(myStack,stackOptions)#Define our stack handler
A stack handler will simply hold the stackTools class with your stack and it's options
Initialise stack (initStack)
stack=stackHandler.initStack(5,int) # Initialise a new stack which can contain 5 integer values
Initialise stack will update the list that is acting as a stack to the correct size with the expected data format
This will most likely never be updated
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
stack-module-0.1.2.tar.gz
(2.8 kB
view hashes)
Built Distribution
Close
Hashes for stack_module-0.1.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9c153ed91d2033df82f939daf841c3822f42b94717491040aa0cffbd6e8c3480 |
|
MD5 | 21bb89f3eb602050603cdbb8d66295a8 |
|
BLAKE2b-256 | 550676293b2b9ae623c275be92e6bd84ff0baf29bda3b2340abed4568fa4f42e |