Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <stdio.h>
- #include <stdlib.h>
- using namespace std;
- struct GENIUS_ARRAY
- {
- int VALUE;
- struct GENIUS_ARRAY* NEXT;
- struct GENIUS_ARRAY* PREVIOUS;
- };
- int main(void)
- {
- int n;
- scanf("%d", &n);
- struct GENIUS_ARRAY* a = (struct GENIUS_ARRAY *)malloc(sizeof(struct GENIUS_ARRAY) * n);
- a->VALUE = 1;
- a->NEXT = a + 1;
- a->PREVIOUS = NULL;
- for (int i = 1; i < n - 1; i++)
- {
- a->VALUE = i + 1;
- a->NEXT = a + 1;
- a->PREVIOUS = a - 1;
- }
- a->VALUE = n;
- a->NEXT = NULL;
- a->PREVIOUS = a - 1;
- int m;
- scanf("%d", &m);
- for (int i = 0; i < m; i++)
- {
- int b, c;
- scanf("%d%d", &b, &c);
- b--;
- c--;
- a[0].PREVIOUS = a + c;
- a[b].PREVIOUS->NEXT = a[c].NEXT;
- a[c + 1].PREVIOUS = a[b].PREVIOUS;
- a[b].PREVIOUS = NULL;
- }
- int index = 0;
- for ( ; index < n; index++)
- {
- if ((a + index)->PREVIOUS == NULL)
- {
- break;
- }
- }
- for ( ; ; )
- {
- cout << a[index].VALUE << " ";
- if (a[index].NEXT = NULL)
- {
- break;
- }
- }
- cout << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement