link list reversal correction
The following code reverses all the links of a linear singly linked list
with head pointer. So if we have: 3->2->5->8->NULL (with head
pointing at 3), then after the function executes 8->5->2->3->NULL (with head
pointing at 8). What is wrong with this
code:
CODE SOLUTION
|
void LinkedList::reverse()
{
node *front=head;
node*back = NULL;
while
(front->next)
{
temp =
front->next;
back =
front;
front->next
= back;
front =
temp;
}
}
|
void LinkedList::reverse()
{
node *front=head;
node*back = NULL;
while (front)
{
= front->next;
}
|
Comments
Post a Comment