File tree 3 files changed +38
-2
lines changed
3 files changed +38
-2
lines changed Original file line number Diff line number Diff line change @@ -2235,8 +2235,8 @@ Com o objetivo de alcançar uma abrangência maior e encorajar novas pessoas a c
2235
2235
</a>
2236
2236
</td>
2237
2237
<td> <!-- Go -->
2238
- <a href="./CONTRIBUTING.md ">
2239
- <img align="center" height="25" src="https://cdn.jsdelivr.net/gh/devicons/devicon/icons/github/github -original.svg" />
2238
+ <a href="./src/go/stack/stack.go ">
2239
+ <img align="center" height="25" src="https://cdn.jsdelivr.net/gh/devicons/devicon/icons/go/go -original.svg" />
2240
2240
</a>
2241
2241
</td>
2242
2242
<td> <!-- Ruby -->
Original file line number Diff line number Diff line change @@ -21,6 +21,7 @@ import (
21
21
"../go/radixsort"
22
22
"../go/selectionsort"
23
23
"../go/shellsort"
24
+ "../go/stack"
24
25
)
25
26
26
27
func main () {
@@ -100,4 +101,13 @@ func main() {
100
101
slice = []int {10 , 1000 , 100000 , 10000000 }
101
102
fmt .Println ("Slice : " , slice )
102
103
fmt .Println ("CalculatePi : " , calculatepi .CalculatePi (slice ))
104
+
105
+ pilha := stack.Stack [int ]{}
106
+ pilha .Push (1 )
107
+ pilha .Push (2 )
108
+ pilha .Push (3 )
109
+ pilha .Push (4 )
110
+ pilha .Pop ()
111
+ fmt .Printf ("Stack: " )
112
+ pilha .Show ()
103
113
}
Original file line number Diff line number Diff line change
1
+ package stack
2
+
3
+ import "fmt"
4
+
5
+ // A simple stack using generics
6
+ type Stack [T any ] struct {
7
+ items []T
8
+ }
9
+
10
+ func (stack * Stack [T ]) Push (value T ) {
11
+ stack .items = append (stack .items , value )
12
+ }
13
+
14
+ func (stack * Stack [T ]) Pop () T {
15
+ n := len (stack .items )
16
+ if n <= 0 {
17
+ panic ("Cannot pop an empty stack!" )
18
+ }
19
+ value := stack .items [n - 1 ]
20
+ stack .items = stack .items [:n - 1 ]
21
+ return value
22
+ }
23
+
24
+ func (stack * Stack [T ]) Show () {
25
+ fmt .Printf ("%v\n " , stack .items )
26
+ }
You can’t perform that action at this time.
0 commit comments