由买买提看人间百态

topics

全部话题 - 话题: nhead
(共0页)
s******o
发帖数: 328
1
inline void connectOne( Node *n, Node *&nHead, Node *&nTmp ) {
if ( n == NULL ) return;
if ( nHead == NULL ) { nHead = nTmp = n; }
else { nTmp->next = n; nTmp = nTmp->next; }
}
void connect(Node *root) {
Node * cHead = root;
while ( cHead != NULL ) {
Node * nHead = NULL, * nTmp = NULL, *cTmp = cHead;
while ( cTmp != NULL ) {
connectOne( cTmp->left, nHead, nTmp );
connectOne( cTmp->right, ... 阅读全帖
s***e
发帖数: 403
2
/**
* Definition for singly-linked list with a random pointer.
* struct RandomListNode {
* int label;
* RandomListNode *next, *random;
* RandomListNode(int x) : label(x), next(NULL), random(NULL) {}
* };
*/
class Solution {
public:
RandomListNode *copyRandomList(RandomListNode *head) {
map corresponding;
corresponding[nullptr] = nullptr;

RandomListNode* nhead = new RandomListNode(0);
RandomListNode* last = ... 阅读全帖
h******c
发帖数: 75
3
来自主题: JobHunting版 - 反转链表递归怎么写?
// input is the head of the list
// return the new head of reverse list
List* reverse(List* head)
{
if(!head || !head->next)
return head;
List* t = head->next;
head->next = NULL;
List* nhead = reverse(t);
t->next = head;
return nhead;
}
(共0页)