s*********e 发帖数: 17 | 1 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
|
t****t 发帖数: 6806 | 2 O(N) space is not allowed for sure |
c*****g 发帖数: 119 | 3 if not allowed, then reverse the list again.
【在 t****t 的大作中提到】 : O(N) space is not allowed for sure
|
t*******l 发帖数: 3662 | 4 if it is not allowed, we can still create a wrapper for each node,
and create a reverse link.
that might require dynamic memory allocation: two pointers for each
node.
【在 t****t 的大作中提到】 : O(N) space is not allowed for sure
|