boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
JobHunting版 - ms面试题目
相关主题
delete a node in linked list
问个reverse linked list
leetcode过的一代工程师
问道G家的面试题。
有人同看Populating Next Right Pointers in Each Node II的recursive写法么?
问了一个链表,1->2->3->4->5, 每两个交换,2->1->4->3->5
一到电面题
【我自己写的LinkedList为什么总有错?】
问了一个链表,1->2->3->4->5, 每两个交换,2->1->4->3->5,
大牛们帮忙,Rverse Nodes in k-Group
相关话题的讨论汇总
话题: node话题: piter话题: pnext话题: head话题: next
进入JobHunting版参与讨论
1 (共1页)
c*******r
发帖数: 309
1
问了一个链表,1->2->3->4->5, 每两个交换,2->1->4->3->5,如果单数
情况返回最后一个。要求recursive和iterative两种方法
这个如何recursive?
P**l
发帖数: 3722
2
不到两个就停下来
够了的话,每次处理完两个,函数call第三个node就行了吧
l*****a
发帖数: 14598
3
void Swap2Nodes(element ** head)
{
current=*head;
if(current==null||current->next==null) return;
element *next,*nextnext;
next=current->next;
nextnext=next->next;
Swap2Nodes(&nextnext);
*head=next;
next->next=current;
current->next=nextnext;
return;
}

【在 c*******r 的大作中提到】
: 问了一个链表,1->2->3->4->5, 每两个交换,2->1->4->3->5,如果单数
: 情况返回最后一个。要求recursive和iterative两种方法
: 这个如何recursive?

Y**B
发帖数: 144
4
是只换数据还是换node的顺序?
q****x
发帖数: 7404
5
i prefer:
Node* swap2nodes(Node* head);

【在 l*****a 的大作中提到】
: void Swap2Nodes(element ** head)
: {
: current=*head;
: if(current==null||current->next==null) return;
: element *next,*nextnext;
: next=current->next;
: nextnext=next->next;
: Swap2Nodes(&nextnext);
: *head=next;
: next->next=current;

q****x
发帖数: 7404
6
node.

【在 Y**B 的大作中提到】
: 是只换数据还是换node的顺序?
l*****a
发帖数: 14598
7
that is fine
then u need two node*

【在 q****x 的大作中提到】
: i prefer:
: Node* swap2nodes(Node* head);

q****x
发帖数: 7404
8
one ah. 7 line is enough.
Node* swap2(Node* head)
{
if ( head != NULL && head->next != NULL ) {
Node* t = head->next;
head->next = swap2(t->next);
t->next = head;
head = t;
}
return head;
}

【在 l*****a 的大作中提到】
: that is fine
: then u need two node*

w****x
发帖数: 2483
9
NODE* SwapNodes(NODE* pHead)
{
assert(NULL != pHead);
if (pHead->pNext == NULL)
return pHead;
NODE* pRet = pHead->pNext;
NODE* pIter = pHead;
NODE* pPrev = NULL;
while (pIter != NULL && pIter->pNext != NULL)
{
if (NULL != pPrev)
pPrev->pNext = pIter->pNext;
NODE* pTmp = pIter->pNext->pNext;
pIter->pNext->pNext = pIter;
pIter->pNext = pTmp;
pPrev = pIter;
pIter = pIter->pNext;
}
return pRet;
}
s*******f
发帖数: 1114
10
Node* SwapNeibor(Node *head){
if (!head || !head->next)
return head;
Node *p = head->next;
Node *q = p->next;
p->next = head;
head->next = SwapNeibor(q);
return p;
}

【在 c*******r 的大作中提到】
: 问了一个链表,1->2->3->4->5, 每两个交换,2->1->4->3->5,如果单数
: 情况返回最后一个。要求recursive和iterative两种方法
: 这个如何recursive?

1 (共1页)
进入JobHunting版参与讨论
相关主题
大牛们帮忙,Rverse Nodes in k-Group
删除node从list, 这个有内存泄露么,怎么释放内存,对于那个被删除的节点?
那个skiplist的题谁来给谢谢
"简单的"linklist的问题
做了一下merge BST
Print a binary tree in level order but starting from leaf node up to root
G题,把binary tree里面的sibling节点连接起来
请教各位大牛一个K-way merge 的问题
攒人品,Twitter 电面题目
贡献一道G家的onsite题和简单面经(已悲剧)
相关话题的讨论汇总
话题: node话题: piter话题: pnext话题: head话题: next