an appendable intlist struct in go that uses maps as its implementations
package main
//file to implement expanding/shrinking intlist with a map
import "fmt"
type IntList struct {
list map[int]int
//for keeping track of placement indices and insertion spots
record map[string]int
}
//creates an IntList and returns it
func createIntList() IntList {
lst := IntList{list:make(map[int]int), record:make(map[string]int)}
lst.record["insert"] = 0
lst.record["last"] = -1
return lst
}
//appends a new element to the end of the list, and updates the insertion and last element positions
func (il IntList) push(elem int) {
il.list[il.record["insert"]] = elem
il.record["insert"] += 1
il.record["last"] += 1
}
func main() {
tester := createIntList()
tester.push(5)
fmt.Println(tester)
//{map[0:5] map[last:0 insert:1]}
}