Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void Swap(element*& first, element*& el1, element*& el2, element*& last)
- {
- bool f = false;
- bool l = false;
- if (el1 == first)
- {
- element* cur = new element;
- cur->prev = NULL;
- cur->next = first;
- first->prev = cur;
- first = cur;
- f = true;
- }
- if (el2 == last)
- {
- cur = new element;
- cur->next = NULL;
- cur->prev = last;
- last->next = cur;
- last = cur;
- l = true;
- }
- if (el1->next == el2 || el2->next == el1)
- {
- el1->prev->next = el2;
- el2->prev = el1->prev;
- el1->next = el2->next;
- el2->next->prev = el1;
- el2->next = el1;
- el1->prev = el2;
- }
- else
- {
- element* tmp1 = new element;
- tmp1->next = el1->next;
- tmp1->prev = el1->prev;
- element* tmp2 = new element;
- tmp2->next = el2->next;
- tmp2->prev = el2->prev;
- el1->prev->next = el2;
- el2->prev = el1->prev;
- el1->next = el2->next;
- el2->next->prev = el1;
- el1->prev = tmp2->prev;
- tmp2->prev->next = el1;
- el2->next = tmp1->next;
- tmp1->next->prev = el2;
- delete tmp1;
- delete tmp2;
- }
- if (f)
- {
- cur = first;
- first = first->next;
- first->prev = NULL;
- delete cur;
- }
- if (l)
- {
- cur = last;
- last = last->prev;
- last->next = NULL;
- delete cur;
- }
- }
Add Comment
Please, Sign In to add comment