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.
108 lines
2.4 KiB
108 lines
2.4 KiB
5 years ago
|
package main
|
||
5 years ago
|
|
||
|
import (
|
||
|
"strconv"
|
||
5 years ago
|
|
||
|
"github.com/01-edu/z01"
|
||
5 years ago
|
|
||
5 years ago
|
correct "./correct"
|
||
5 years ago
|
student "./student"
|
||
|
)
|
||
|
|
||
|
type Node10 = student.NodeL
|
||
5 years ago
|
type List10 = correct.List
|
||
|
type NodeS10 = correct.NodeL
|
||
5 years ago
|
type ListS10 = student.List
|
||
|
|
||
|
func listToStringStu12(l *ListS10) string {
|
||
|
var res string
|
||
|
it := l.Head
|
||
|
for it != nil {
|
||
|
switch it.Data.(type) {
|
||
|
case int:
|
||
|
res += strconv.Itoa(it.Data.(int)) + "-> "
|
||
|
case string:
|
||
|
res += it.Data.(string) + "-> "
|
||
|
}
|
||
|
it = it.Next
|
||
|
}
|
||
|
res += "<nil>"
|
||
|
return res
|
||
|
}
|
||
|
|
||
|
func listPushBackTest10(l *ListS10, l1 *List10, data interface{}) {
|
||
|
n := &Node10{Data: data}
|
||
|
n1 := &NodeS10{Data: data}
|
||
|
if l.Head == nil {
|
||
|
l.Head = n
|
||
|
} else {
|
||
|
iterator := l.Head
|
||
|
for iterator.Next != nil {
|
||
|
iterator = iterator.Next
|
||
|
}
|
||
|
iterator.Next = n
|
||
|
}
|
||
|
if l1.Head == nil {
|
||
|
l1.Head = n1
|
||
|
} else {
|
||
|
iterator1 := l1.Head
|
||
|
for iterator1.Next != nil {
|
||
|
iterator1 = iterator1.Next
|
||
|
}
|
||
|
iterator1.Next = n1
|
||
|
}
|
||
|
}
|
||
|
|
||
5 years ago
|
func comparFuncList10(l *List10, l1 *ListS10, data interface{}) {
|
||
5 years ago
|
for l.Head != nil || l1.Head != nil {
|
||
|
if (l.Head == nil && l1.Head != nil) || (l.Head != nil && l1.Head == nil) {
|
||
5 years ago
|
z01.Fatalf("\ndata used: %v\nstudent list:%s\nlist:%s\n\nListRemoveIf() == %v instead of %v\n\n",
|
||
5 years ago
|
data, listToStringStu12(l1), correct.ListToString(l.Head), l1.Head, l.Head)
|
||
5 years ago
|
}
|
||
|
if l.Head.Data != l1.Head.Data {
|
||
|
z01.Fatalf("\ndata used: %v\nstudent list:%s\nlist:%s\n\nListRemoveIf() == %v instead of %v\n\n",
|
||
5 years ago
|
data, listToStringStu12(l1), correct.ListToString(l.Head), l1.Head.Data, l.Head.Data)
|
||
5 years ago
|
}
|
||
|
l.Head = l.Head.Next
|
||
|
l1.Head = l1.Head.Next
|
||
|
}
|
||
|
}
|
||
|
|
||
5 years ago
|
// removes all the elements that are equal to a value
|
||
|
func main() {
|
||
|
link1 := &List10{}
|
||
5 years ago
|
link2 := &ListS10{}
|
||
|
var index int
|
||
5 years ago
|
table := []correct.NodeTest{}
|
||
5 years ago
|
|
||
5 years ago
|
table = correct.ElementsToTest(table)
|
||
5 years ago
|
|
||
|
table = append(table,
|
||
5 years ago
|
correct.NodeTest{
|
||
5 years ago
|
Data: []interface{}{"hello", "hello1", "hello2", "hello3"},
|
||
|
},
|
||
|
)
|
||
|
|
||
|
for _, arg := range table {
|
||
|
for i := 0; i < len(arg.Data); i++ {
|
||
5 years ago
|
listPushBackTest10(link2, link1, arg.Data[i])
|
||
5 years ago
|
}
|
||
|
aux := len(arg.Data) - 1
|
||
|
|
||
|
index = z01.RandIntBetween(0, aux)
|
||
5 years ago
|
if link1.Head != nil && link2.Head != nil {
|
||
5 years ago
|
cho := arg.Data[index]
|
||
|
student.ListRemoveIf(link2, cho)
|
||
5 years ago
|
correct.ListRemoveIf(link1, cho)
|
||
5 years ago
|
comparFuncList10(link1, link2, cho)
|
||
5 years ago
|
} else {
|
||
|
student.ListRemoveIf(link2, 1)
|
||
5 years ago
|
correct.ListRemoveIf(link1, 1)
|
||
5 years ago
|
comparFuncList10(link1, link2, 1)
|
||
5 years ago
|
}
|
||
|
|
||
5 years ago
|
link1 = &List10{}
|
||
5 years ago
|
link2 = &ListS10{}
|
||
|
}
|
||
|
}
|