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 = (struct Elem*)malloc(sizeof(struct Elem));
- x->v = -777777777;
- x->prev = x;
- x->next = x;
- return x;
- }
- void InsertSort(struct Elem *l)
- {
- }
- 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 = (struct Elem*)malloc(sizeof(struct Elem));
- struct Elem *now = (struct Elem*)malloc(sizeof(struct Elem));
- for (i = 0; i < n; i++) {
- if (i == 0) {
- scanf("%d ", &x);
- cur->v = x;
- cur->prev = l;
- l->next = cur;
- now = cur;
- }
- if (i < n - 1 && i != 0) {
- scanf("%d ", &x);
- cur->v = x;
- cur->prev = now;
- now->next = cur;
- now = cur;
- }
- if (i == n - 1) {
- scanf("%d", &x);
- 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");
- free(l);
- free(cur);
- free(now);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement