MCPcopy Create free account
hub / github.com/TheAlgorithms/Go / Remove

Method Remove

structure/dynamicarray/dynamicarray.go:51–64  ·  view source on GitHub ↗

Remove function is remove an element with the index

(index int)

Source from the content-addressed store, hash-verified

49
50// Remove function is remove an element with the index
51func (da *DynamicArray) Remove(index int) error {
52 err := da.CheckRangeFromIndex(index)
53
54 if err != nil {
55 return err
56 }
57
58 copy(da.ElementData[index:], da.ElementData[index+1:da.Size])
59 da.ElementData[da.Size-1] = nil
60
61 da.Size--
62
63 return nil
64}
65
66// Get function is return one element with the index of array
67func (da *DynamicArray) Get(index int) (any, error) {

Callers 1

TestDynamicArrayFunction · 0.95

Calls 1

CheckRangeFromIndexMethod · 0.95

Tested by 1

TestDynamicArrayFunction · 0.76