udpate reverse_linked_number

This commit is contained in:
xwy@asus 2019-09-04 02:18:53 +01:00
parent a75821353d
commit 4df154882a

View File

@ -28,41 +28,28 @@ st_node *node_sum_r(int carry_up, st_node *p, st_node *q)
st_node *node_sum(st_node *p, st_node *q)
{
if (!p || !q) {
return 0;
}
if (!p || !q) return 0;
return node_sum_r(0, p, q);
}
st_node *str_to_node(char *num)
{
st_node *node = 0;
for (; *num; num++) {
st_node *new = node_alloc(*num - '0', 0);
new->next = node;
node = new;
}
return node;
if (!*num) return 0;
return node_alloc(*num - '0', str_to_node(num + 1));
}
int node_len(st_node *node)
void node_show_r(st_node *node)
{
int len = 0;
for (; node; node = node->next) len += 1;
return len;
if (!node) return;
node_show_r(node->next);
printf("%d", node->val);
return;
}
void node_show(st_node *node)
{
int len = node_len(node);
char *buf = (char *)malloc(len + 1);
char *p = buf + len;
*p-- = 0;
for (; node; node = node->next) {
*p-- = node->val + '0';
}
printf("%s\n", buf);
free(buf);
node_show_r(node);
printf("\n");
return;
}