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.
25 lines
389 B
25 lines
389 B
package correct |
|
|
|
// structures for the linked lists |
|
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 |
|
}
|
|
|