Slice remove elements from the middle position

To remove the intermediate element, the remaining elements needed for a whole move, append or the same copy can be done in situ:

  1. a = []int{1, 2, 3, ...}
  2. a = append (a [: i], a [+ 1:] ...) // delete an intermediate element
  3. a = append (a [: i], a [i + N:] ...) // delete the middle N elements
  4. a = a [: i + copy (a [i:], a [i + 1:])] // delete an intermediate element
  5. a = a [: i + copy (a [i:], a [i + N:])] // delete the middle N elements

Guess you like

Origin www.cnblogs.com/qiaoyanlin/p/12005355.html