由买买提看人间百态

topics

全部话题 - 话题: pphead
(共0页)
s*********e
发帖数: 17
1
来自主题: Programming版 - how to reverse a HUGE list?
How can you print singly linked list in reverse order? (it's a huge list and
you cant use recursion) ?
大家有没有更好的方法 print “HUGE” list in reverse order? 谢谢!
BOOL ReverseList(node** pphead)
{
if(*pphead == NULL)
return FALSE;
node* pNode = NULL;
node* pTmp;

while(*pphead != NULL)
{
// tmp storage of header pointer
pTmp = (*pphead)->pNext;

// reverse
(*pphead)->pNext = pNode;

// pNode pointer moves one
s*********e
发帖数: 17
2
来自主题: Programming版 - swap every second node?
I give you a singly linked Linked List. Write a function to swap every second
node. [ie - 1->2->3->4->5->| becomes 2->1->4->3->5->|]
大家有没有更好的办法?
BOOL SwapList(node** pphead)
{
if(*pphead == NULL)
return FALSE;
// two pointers
node* pNode1 = *pphead;
node* pNode2 = (*pphead)->pNext;
*pphead = pNode2;
while(pNode2->pNext != NULL)
{
// two temporay pointers
node* pTmp1 = pNode1->pNext->pNext;
node* pTmp2 = pNode2->pNext->pNext;

(共0页)