Showing posts with label LINKED LIST PROBLEMS. Show all posts
Showing posts with label LINKED LIST PROBLEMS. Show all posts

Sunday, August 22, 2010

Reverse the Linked list

Reversing the linked list.....

void reverse()
{
mynode *p , *q , *r ;
if( head == NULL)
{
return ;
}
p = head ;
q = p -> next ;
p -> next = NULL ;
while( q != NULL )
{
r = q -> next ;
q -> next = p ;
p = q ;
q = r ;
}
head = p;
}

TIME COMPLEXITY : O(n)