Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- struct Elem {
- struct Elem *prev, *next;
- int v;
- };
- struct Elem InitDoubleLinkedList()
- {
- struct Elem x;
- x.v = -777777777;
- x.prev = &x;
- x.next = &x;
- return x;
- }
- void InsertSort(struct Elem *data, int n)
- {
- struct Elem that, this;
- int i = 1, j;
- while (i < n) {
- i++;
- }
- }
- int main()
- {
- int n, i, x, j;
- scanf("%d\n", &n);
- if (n == 1) {
- scanf("%d", &i);
- printf("%d\n", i);
- }
- else {
- struct Elem l = InitDoubleLinkedList();
- struct Elem cur, now;
- for (i = 0; i < n; i++) {
- if (i == 0) {
- scanf("%d ", &x);
- cur.v = x;
- cur.prev = &l;
- l.next = &cur;
- }
- if (i < n - 1 && i != 0) {
- scanf("%d ", &x);
- now = l;
- for (j = 0; j <= i; j++) now = *now.next;
- cur.v = x;
- cur.prev = &now;
- now.next = &cur;
- }
- if (i == n - 1) {
- scanf("%d", &x);
- now = l;
- for (j = 0; j <= i; j++) now = *now.next;
- cur.v = x;
- cur.prev = &now;
- cur.next = &l;
- now.next = &cur;
- }
- }
- cur = *l.next;
- for (i = 0; i < n; i++) {
- printf("%d ", cur.v);
- cur = *cur.next;
- }
- printf("\n");
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement