Steve Thielemann 2 anni fa
parent
commit
d4a3a3b59c
1 ha cambiato i file con 18 aggiunte e 0 eliminazioni
  1. 18 0
      door/utilities.go

+ 18 - 0
door/utilities.go

@@ -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
+}