Reverse a linked list in C++


void linkedlist::reverse()
{
    element *ptr= head;
    element *nextptr= ptr->next;
    while(nextptr)
    {
        element *temp = nextptr->next;
        nextptr->next = ptr;
        ptr = nextptr;
        nextptr = temp;
    }
    head->next = 0;
    head = ptr;
}

In

Leave a Reply

Your email address will not be published. Required fields are marked *