diff options
Diffstat (limited to '9618-42-mj-2022/Question1_J22.py')
-rw-r--r-- | 9618-42-mj-2022/Question1_J22.py | 12 |
1 files changed, 4 insertions, 8 deletions
diff --git a/9618-42-mj-2022/Question1_J22.py b/9618-42-mj-2022/Question1_J22.py index 3b8e5c5..2bee365 100644 --- a/9618-42-mj-2022/Question1_J22.py +++ b/9618-42-mj-2022/Question1_J22.py @@ -1,19 +1,17 @@ #1a -StackData = [None for i in range(10)] # global variable because defined in the main script execution context. -StackPointer = 0 # global variable because defined in the main script execution context. +global StackData +global StackPointer +StackData = [None for i in range(10)] # global variable +StackPointer = 0 # global variable #1b def OutputAllElements(): - global StackData - global StackPointer for dataItem in StackData: print(dataItem) print(f"Stack pointer: {StackPointer}") #1c def Push(push_item: int): - global StackData - global StackPointer if StackPointer == len(StackData): return False StackData[StackPointer] = push_item @@ -21,8 +19,6 @@ def Push(push_item: int): return True # 1 e i def Pop(): - global StackData - global StackPointer if StackPointer == 0: return -1 StackPointer -= 1 |