【发布时间】:2019-02-07 11:23:43
【问题描述】:
/** Helper function to return the index-th node in the linked list. */
SinglyListNode* getNode(int index) {
SinglyListNode *cur = head;
for (int i = 0; i < index && cur; ++i) {
cur = cur->next;
}
return cur;
}
/** Helper function to return the last node in the linked list. */
SinglyListNode* getTail() {
SinglyListNode *cur = head;
while (cur && cur->next) {
cur = cur->next;
}
return cur;
}
/** Get the value of the index-th node in the linked list. If the index is invalid, return -1. */
int get(int index) {
SinglyListNode *cur = getNode(index);
return cur == NULL ? -1 : cur->val;
}
这个“返回 cur == NULL ? -1:cur->val; ”
我把这个语法弄糊涂了,有人能把这句话分开吗?
【问题讨论】:
-
称为三元运算符或条件运算符。看看:cplusplus.com/articles/1AUq5Di1
标签: c++