avatar
how to reverse a HUGE list?# Programming - 葵花宝典
s*e
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
avatar
t*t
2
O(N) space is not allowed for sure
avatar
c*g
3
if not allowed, then reverse the list again.

【在 t****t 的大作中提到】
: O(N) space is not allowed for sure
avatar
t*l
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
相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。