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)
No comments:
Post a Comment