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