Friday, April 9, 2010

Reverse a singly linked listeverse a singly linked list

//Iterative reverse 
 
Void ReverseList(node* head)
{
        node
*temp,*current,*result;
        temp
=null;
        result
=null;
        current
=head;
       
while(current!=null)
       
{
                temp
=current->next;//point to next element
                current
->next=result;//point current element's next to prev element
                result
=current;//point prev element to current element
                current
=temp;
       
}
   head
=result;
 
} 

No comments:

Post a Comment