C - Ternary operate to if else

前端 未结 2 1402
一个人的身影
一个人的身影 2021-01-29 16:06

Can someone help me convert this line to an if-else statement?

temp = head->left ? head->left : head->right;

Thanks!

相关标签:
2条回答
  • 2021-01-29 16:44
    if (head->left) 
    {
      temp = head->left;
    }
    else
    {
      temp = head->right;
    }
    
    0 讨论(0)
  • 2021-01-29 16:53
    if ( head->left )
        temp = head->left;
    else
        temp = head->right;
    
    0 讨论(0)
提交回复
热议问题