fbpx
分類
Computers

兩段話與結論

第一段話

void print_list(node head)
{
  node current = head;
  while(current)
  {
    printf("-> %s ", current->data);
    if(!current->next_node) printf("$ \n");
    current = current->next_node;
  }
}

第二段話

void print_list_lazy(node current)
{
  if(!current) return;
  printf("-> %s %s", current->data, current->next_node? "":"$\n");
  print_list_lazy(current->next_node);
}

兩段程式都可以做到同樣的效果,但是後者使用的是遞迴。
..所以呢?

遞迴是好物 (飄)