mirror of
https://github.com/golang/go.git
synced 2025-05-05 23:53:05 +00:00
sort Pushes & Pops.
parent
f1e07061fb
commit
9ade7aa9a7
@ -86,9 +86,9 @@ s[i] = x
|
|||||||
a = append(a[:i], append(b, a[i:]...)...)
|
a = append(a[:i], append(b, a[i:]...)...)
|
||||||
```
|
```
|
||||||
|
|
||||||
#### Pop Front/Shift
|
#### Push
|
||||||
```go
|
```go
|
||||||
x, a = a[0], a[1:]
|
a = append(a, x)
|
||||||
```
|
```
|
||||||
|
|
||||||
#### Pop
|
#### Pop
|
||||||
@ -96,16 +96,16 @@ x, a = a[0], a[1:]
|
|||||||
x, a = a[len(a)-1], a[:len(a)-1]
|
x, a = a[len(a)-1], a[:len(a)-1]
|
||||||
```
|
```
|
||||||
|
|
||||||
#### Push
|
|
||||||
```go
|
|
||||||
a = append(a, x)
|
|
||||||
```
|
|
||||||
|
|
||||||
#### Push Front/Unshift
|
#### Push Front/Unshift
|
||||||
```go
|
```go
|
||||||
a = append([]T{x}, a...)
|
a = append([]T{x}, a...)
|
||||||
```
|
```
|
||||||
|
|
||||||
|
#### Pop Front/Shift
|
||||||
|
```go
|
||||||
|
x, a = a[0], a[1:]
|
||||||
|
```
|
||||||
|
|
||||||
## Additional Tricks
|
## Additional Tricks
|
||||||
### Filtering without allocating
|
### Filtering without allocating
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user