void pairWiseSwap(Node *&head)

{

if (head == NULL || head->next == NULL)

return;

Node *prev = head;

Node *curr = head->next;

head = curr;

while (1)

{

Node *next = curr->next;

curr->next = prev;

if (next == NULL || next->next == NULL)

{

prev->next = next;

break;

}

prev->next = next->next;

prev = next;

curr = prev->next;

}

}

{

if (head == NULL || head->next == NULL)

return;

Node *prev = head;

Node *curr = head->next;

head = curr;

while (1)

{

Node *next = curr->next;

curr->next = prev;

if (next == NULL || next->next == NULL)

{

prev->next = next;

break;

}

prev->next = next->next;

prev = next;

curr = prev->next;

}

}

nice .

ReplyDelete