1
2
3
4
5 package a
6
7 type Ordered interface {
8 ~int | ~int8 | ~int16 | ~int32 | ~int64 |
9 ~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr |
10 ~float32 | ~float64 |
11 ~string
12 }
13
14
15 type List[T Ordered] struct {
16 Next *List[T]
17 Val T
18 }
19
20 func (l *List[T]) Largest() T {
21 var max T
22 for p := l; p != nil; p = p.Next {
23 if p.Val > max {
24 max = p.Val
25 }
26 }
27 return max
28 }
29
30 type OrderedNum interface {
31 ~int | ~int8 | ~int16 | ~int32 | ~int64 |
32 ~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr |
33 ~float32 | ~float64
34 }
35
36
37 type ListNum[T OrderedNum] struct {
38 Next *ListNum[T]
39 Val T
40 }
41
42 const Clip = 5
43
44
45 func (l *ListNum[T]) ClippedLargest() T {
46 var max T
47 for p := l; p != nil; p = p.Next {
48 if p.Val > max && p.Val < Clip {
49 max = p.Val
50 }
51 }
52 return max
53 }
54
View as plain text