|
@@ -0,0 +1,18 @@
|
|
|
|
+package door
|
|
|
|
+
|
|
|
|
+func ArrayDelete[T any](stack *[]T, pos int) (T, bool) {
|
|
|
|
+ var result T
|
|
|
|
+ /*
|
|
|
|
+ https://stackoverflow.com/questions/33834742/remove-and-adding-elements-to-array-in-go-lang
|
|
|
|
+ https://github.com/golang/go/wiki/SliceTricks
|
|
|
|
+ */
|
|
|
|
+ if pos < 0 || pos > len(*stack) {
|
|
|
|
+ return result, false
|
|
|
|
+ }
|
|
|
|
+ result = (*stack)[pos]
|
|
|
|
+ copy((*stack)[pos:], (*stack)[pos+1:])
|
|
|
|
+ // var temp T
|
|
|
|
+ // (*stack)[len(*stack)-1] = temp
|
|
|
|
+ *stack = (*stack)[:len(*stack)-1]
|
|
|
|
+ return result, true
|
|
|
|
+}
|