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.
30 lines
382 B
30 lines
382 B
![]()
4 years ago
|
package solutions
|
||
|
|
||
|
func ListSort(l *NodeI) *NodeI {
|
||
|
|
||
|
Head := l
|
||
|
if Head == nil {
|
||
|
return nil
|
||
|
}
|
||
|
Head.Next = ListSort(Head.Next)
|
||
|
|
||
|
if Head.Next != nil && Head.Data > Head.Next.Data {
|
||
|
Head = move(Head)
|
||
|
}
|
||
|
return Head
|
||
|
}
|
||
|
|
||
|
func move(l *NodeI) *NodeI {
|
||
|
p := l
|
||
|
n := l.Next
|
||
|
ret := n
|
||
|
|
||
|
for n != nil && l.Data > n.Data {
|
||
|
p = n
|
||
|
n = n.Next
|
||
|
}
|
||
|
p.Next = l
|
||
|
l.Next = n
|
||
|
return ret
|
||
|
}
|