Your Ad Here
0

How do you write a function that can reverse a linked-list?

Posted by The Blogger on 8:18 AM in
Answer:

void reverselist(void)
{
if(head==0)
return;
if(head->next==0)
return;
if(head->next==tail)
{
head->next = 0;
tail->next = head;
}
else
{
node* pre = head;
node* cur = head->next;
node* curnext = cur->next;
head->next = 0;
cur-> next = head;

for(; curnext!=0; )
{
cur->next = pre;
pre = cur;
cur = curnext;
curnext = curnext->next;
}

curnext->next = cur;
}
}



interview questions and answers, interview question How do you write a function that can reverse a linked-list, How do you write a function that can reverse a linked-list, reverse a linked list, linked list

0 Comments

Post a Comment

Your Ad Here

Copyright © 2009 Interview Questions and Answers