|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"../lib"
|
|
|
|
"./correct"
|
|
|
|
)
|
|
|
|
|
|
|
|
type stuNode = NodeAddL
|
|
|
|
type solNode = correct.NodeAddL
|
|
|
|
|
|
|
|
func stuPushFront(node *stuNode, num int) *stuNode {
|
|
|
|
tmp := &stuNode{Num: num}
|
|
|
|
tmp.Next = node
|
|
|
|
return tmp
|
|
|
|
}
|
|
|
|
|
|
|
|
func stuNumToList(num int) *stuNode {
|
|
|
|
var res *stuNode
|
|
|
|
for num > 0 {
|
|
|
|
res = stuPushFront(res, num%10)
|
|
|
|
num /= 10
|
|
|
|
}
|
|
|
|
return res
|
|
|
|
}
|
|
|
|
|
|
|
|
func stuListToNum(node *stuNode) int {
|
|
|
|
var n int
|
|
|
|
|
|
|
|
for tmp := node; tmp != nil; tmp = tmp.Next {
|
|
|
|
n = n*10 + tmp.Num
|
|
|
|
}
|
|
|
|
return n
|
|
|
|
}
|
|
|
|
|
|
|
|
func solPushFront(node *solNode, num int) *solNode {
|
|
|
|
tmp := &solNode{Num: num}
|
|
|
|
tmp.Next = node
|
|
|
|
return tmp
|
|
|
|
}
|
|
|
|
|
|
|
|
func solNumToList(num int) *solNode {
|
|
|
|
var res *solNode
|
|
|
|
for num > 0 {
|
|
|
|
res = solPushFront(res, num%10)
|
|
|
|
num /= 10
|
|
|
|
}
|
|
|
|
return res
|
|
|
|
}
|
|
|
|
|
|
|
|
func solListToNum(node *solNode) int {
|
|
|
|
var n int
|
|
|
|
|
|
|
|
for tmp := node; tmp != nil; tmp = tmp.Next {
|
|
|
|
n = n*10 + tmp.Num
|
|
|
|
}
|
|
|
|
return n
|
|
|
|
}
|
|
|
|
|
Refactor & Beautify & destruction commit
return early, remove else branches, reorder conditions and top-level functions, remove empty lines, remove unnecessary append(), fix typos, stop using testing package, remove dead code, fix mistakes in subjects, tests and solutions, remove disclaimers, reformat comments, simplify solutions, tests, add more instructions to subjects, remove obsolete files, etc.
Some of the reasons behind those modifications will be added to good-practices.en.md
Some of the exercises are now broken, they will have to be fixed, most of them have a "TODO:" comment.
5 years ago
|
|
|
func compareNodes(stuResult *stuNode, solResult *solNode, num1 int) {
|
|
|
|
if stuResult != nil && solResult != nil {
|
|
|
|
stuNum := stuListToNum(stuResult)
|
|
|
|
solNum := solListToNum(solResult)
|
|
|
|
if stuNum != solNum {
|
|
|
|
lib.Fatalf("\nReverse(%d) == %v instead of %v\n\n",
|
|
|
|
num1, stuNum, solNum)
|
|
|
|
}
|
|
|
|
} else if stuResult != nil && solResult == nil {
|
|
|
|
stuNum := stuListToNum(stuResult)
|
|
|
|
lib.Fatalf("\nReverse(%d) == %v instead of %v\n\n",
|
|
|
|
num1, stuNum, "")
|
|
|
|
} else if stuResult == nil && solResult != nil {
|
|
|
|
solNum := solListToNum(solResult)
|
|
|
|
lib.Fatalf("\nReverse(%d) == %v instead of %v\n\n",
|
|
|
|
num1, "", solNum)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Refactor & Beautify & destruction commit
return early, remove else branches, reorder conditions and top-level functions, remove empty lines, remove unnecessary append(), fix typos, stop using testing package, remove dead code, fix mistakes in subjects, tests and solutions, remove disclaimers, reformat comments, simplify solutions, tests, add more instructions to subjects, remove obsolete files, etc.
Some of the reasons behind those modifications will be added to good-practices.en.md
Some of the exercises are now broken, they will have to be fixed, most of them have a "TODO:" comment.
5 years ago
|
|
|
func main() {
|
|
|
|
table := []int{123456543}
|
|
|
|
|
|
|
|
table = append(table, lib.MultRandIntBetween(0, 1000000000)...)
|
|
|
|
for _, arg := range table {
|
Refactor & Beautify & destruction commit
return early, remove else branches, reorder conditions and top-level functions, remove empty lines, remove unnecessary append(), fix typos, stop using testing package, remove dead code, fix mistakes in subjects, tests and solutions, remove disclaimers, reformat comments, simplify solutions, tests, add more instructions to subjects, remove obsolete files, etc.
Some of the reasons behind those modifications will be added to good-practices.en.md
Some of the exercises are now broken, they will have to be fixed, most of them have a "TODO:" comment.
5 years ago
|
|
|
stuResult := Reverse(stuNumToList(arg))
|
|
|
|
solResult := correct.Reverse(solNumToList(arg))
|
|
|
|
|
Refactor & Beautify & destruction commit
return early, remove else branches, reorder conditions and top-level functions, remove empty lines, remove unnecessary append(), fix typos, stop using testing package, remove dead code, fix mistakes in subjects, tests and solutions, remove disclaimers, reformat comments, simplify solutions, tests, add more instructions to subjects, remove obsolete files, etc.
Some of the reasons behind those modifications will be added to good-practices.en.md
Some of the exercises are now broken, they will have to be fixed, most of them have a "TODO:" comment.
5 years ago
|
|
|
compareNodes(stuResult, solResult, arg)
|
|
|
|
}
|
|
|
|
}
|