File tree Expand file tree Collapse file tree 2 files changed +58
-0
lines changed
Expand file tree Collapse file tree 2 files changed +58
-0
lines changed Original file line number Diff line number Diff line change 1+ package slice_
2+
3+ import "fmt"
4+
5+ func reverseInts (s []int ) {
6+
7+ var (
8+ first = 0
9+ last = len (s ) - 1
10+ )
11+
12+ for first < last {
13+ s [first ], s [last ] = s [last ], s [first ]
14+ first ++
15+ last --
16+ }
17+ }
18+
19+ func reverseStrs (s []string ) {
20+
21+ var (
22+ first = 0
23+ last = len (s ) - 1
24+ )
25+
26+ for first < last {
27+ s [first ], s [last ] = s [last ], s [first ]
28+ first ++
29+ last --
30+ }
31+ }
32+
33+ func SliceReverse () error {
34+
35+ var (
36+ ints = []int {
37+ 1 , 2 , 3 , 4 , 5 ,
38+ }
39+
40+ strs = []string {
41+ "hello" , "world" ,
42+ }
43+
44+ f = func (i []int , s []string ) {
45+ fmt .Printf ("[original]\t ints[%v]\t strs[%v]\n " , ints , strs )
46+ }
47+ )
48+
49+ f (ints , strs )
50+
51+ reverseInts (ints )
52+ reverseStrs (strs )
53+
54+ f (ints , strs )
55+
56+ return nil
57+ }
Original file line number Diff line number Diff line change @@ -68,6 +68,7 @@ func (m SampleMapping) MakeMapping() {
6868 m ["slice03" ] = slice_ .Slice03
6969 m ["slice04" ] = slice_ .Slice04
7070 m ["slice05" ] = slice_ .Slice05
71+ m ["slice_reverse" ] = slice_ .SliceReverse
7172 m ["comment01" ] = comments .Comment01
7273 m ["closure01" ] = closure .Closure01
7374 m ["string01" ] = string_ .String01
You can’t perform that action at this time.
0 commit comments