Remove function is remove an element with the index
(index int)
| 49 | |
| 50 | // Remove function is remove an element with the index |
| 51 | func (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 |
| 67 | func (da *DynamicArray) Get(index int) (any, error) { |