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.
26 lines
389 B
26 lines
389 B
4 years ago
|
package correct
|
||
5 years ago
|
|
||
4 years ago
|
// structures for the linked lists
|
||
5 years ago
|
type NodeI struct {
|
||
|
Data int
|
||
|
Next *NodeI
|
||
|
}
|
||
|
|
||
|
func SortListInsert(l *NodeI, data_ref int) *NodeI {
|
||
|
n := &NodeI{Data: data_ref}
|
||
|
n.Next = nil
|
||
|
|
||
|
if l == nil || l.Data >= n.Data {
|
||
|
n.Next = l
|
||
|
return n
|
||
|
}
|
||
|
temp := l
|
||
|
for temp.Next != nil && temp.Next.Data < n.Data {
|
||
|
temp = temp.Next
|
||
|
}
|
||
|
n.Next = temp.Next
|
||
|
temp.Next = n
|
||
|
|
||
|
return l
|
||
|
}
|