mirror of https://github.com/01-edu/public.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
43 lines
779 B
43 lines
779 B
5 years ago
|
## sortlist
|
||
6 years ago
|
|
||
|
### Instructions
|
||
|
|
||
6 years ago
|
Write a function that must:
|
||
6 years ago
|
|
||
5 years ago
|
- Sort the list given as a parameter, using the function cmp to select the order to apply,
|
||
6 years ago
|
|
||
5 years ago
|
- Return a pointer to the first element of the sorted list.
|
||
6 years ago
|
|
||
6 years ago
|
Duplications must remain.
|
||
6 years ago
|
|
||
6 years ago
|
Inputs will always be consistent.
|
||
6 years ago
|
|
||
6 years ago
|
The `type NodeList` must be used.
|
||
6 years ago
|
|
||
6 years ago
|
Functions passed as `cmp` will always return `true` if `a` and `b` are in the right order, otherwise it will return `false`.
|
||
|
|
||
|
### Expected function
|
||
|
|
||
|
```go
|
||
6 years ago
|
type Nodelist struct {
|
||
|
Data int
|
||
|
Next *Nodelist
|
||
|
}
|
||
|
|
||
6 years ago
|
func SortList (l *NodeList, cmp func(a,b int) bool) *NodeList{
|
||
|
|
||
|
}
|
||
|
```
|
||
|
|
||
5 years ago
|
- For example, the following function used as `cmp` will sort the list in ascending order :
|
||
6 years ago
|
|
||
|
```go
|
||
|
func ascending(a, b int) bool{
|
||
|
if a <= b {
|
||
|
return true
|
||
|
} else {
|
||
|
return false
|
||
|
}
|
||
|
}
|
||
6 years ago
|
```
|