小编use*_*817的帖子

了解链接列表中的cdr和car差异

我想知道之间的区别setcdr,setcar,cdrcar.我知道car是指节点的值,而cdr函数是指节点中的下一个指针,但我不明白这些差异.

setcdr函数:

void setcdr( Node* p, Node* q ) {

    assert (p != nullptr);
    p->next = q;
}
Run Code Online (Sandbox Code Playgroud)

void,那么如何设置链表呢?不应该退货Node吗?

//returns the data field of the Node

// if p is the nullptr, we cannot get its data ...exit abruptly

int car( Node* p ) {

    assert (p != nullptr);
    return( p->value );
}

// returns the next field of the Node

// …
Run Code Online (Sandbox Code Playgroud)

c++ pointers

1
推荐指数
1
解决办法
529
查看次数

标签 统计

c++ ×1

pointers ×1