-
Notifications
You must be signed in to change notification settings - Fork 8
/
Beginners - Return Stack from Function.monkey2
54 lines (45 loc) · 1.12 KB
/
Beginners - Return Stack from Function.monkey2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#Import "<std>"
#Import "<mojo>"
Using std..
Using mojo..
Class MyWindow Extends Window
Method New()
'Create a new int list
Local mystack:Stack<Int>
mystack = New Stack<Int>
' add some values to the list
mystack.Add(10)
mystack.Add(20)
mystack.Add(30)
' increase the ints using this function
mystack = incstack(mystack)
' print the output to the console
For Local i:=Eachin mystack
Print i
Next
End method
Method OnRender( canvas:Canvas ) Override
App.RequestRender() ' Activate this method
' if key escape then quit
If Keyboard.KeyReleased(Key.Escape) Then App.Terminate()
End Method
End Class
' Here we create a function that returns a list and takes in
' a list. (it increases the ints in the in list bu 1)
'
Function incstack:Stack<Int>(in:Stack<Int>)
' Create a local list
Local out:Stack<Int> = New Stack<Int>
'loop through the inputted list
For Local i:=Eachin in
' add new value based on old value to the out list
out.Add(i+1)
Next
' return the out list from the function
Return out
End Function
Function Main()
New AppInstance
New MyWindow
App.Run()
End Function