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.
 
 
lavos/cap3/ex7.go

26 lines
558 B

package cap3
// Ex7 低位到高位输出正整数的数字
func Ex7(num uint64, algoType AlgoType, callback func(digit uint8)) {
switch algoType {
case AlgoTypeRecursion:
Ex7Recursion(num, callback)
default:
Ex7NoneRecursion(num, callback)
}
}
func Ex7Recursion(num uint64, callback func(digit uint8)) {
if num < 10 {
callback(uint8(num))
} else {
callback(uint8(num % 10))
Ex7Recursion(num/10, callback)
}
}
func Ex7NoneRecursion(num uint64, callback func(digit uint8)) {
for i := num; i >= 1; i /= 10 {
callback(uint8(i % 10))
}
}