Advertisement
Void-voiD

Untitled

Dec 22nd, 2018
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.69 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. struct Elem {
  5. struct Elem *prev, *next;
  6. int v;
  7. };
  8.  
  9. struct Elem *InitDoubleLinkedList()
  10. {
  11. struct Elem *x = (struct Elem*)malloc(sizeof(struct Elem));
  12. x->v = -777777777;
  13. x->prev = x;
  14. x->next = x;
  15. return x;
  16. }
  17.  
  18. void InsertSort(struct Elem *l)
  19. {
  20.  
  21. }
  22.  
  23. int main()
  24. {
  25. int n, i, x, j;
  26. scanf("%d\n", &n);
  27. if (n == 1) {
  28. scanf("%d", &i);
  29. printf("%d\n", i);
  30. }
  31. else {
  32. struct Elem *l = InitDoubleLinkedList();
  33. struct Elem *cur = (struct Elem*)malloc(sizeof(struct Elem));
  34. struct Elem *now = (struct Elem*)malloc(sizeof(struct Elem));
  35. for (i = 0; i < n; i++) {
  36. if (i == 0) {
  37. scanf("%d ", &x);
  38. cur->v = x;
  39. cur->prev = l;
  40. l->next = cur;
  41. now = cur;
  42. }
  43. if (i < n - 1 && i != 0) {
  44. scanf("%d ", &x);
  45. cur->v = x;
  46. cur->prev = now;
  47. now->next = cur;
  48. now = cur;
  49. }
  50. if (i == n - 1) {
  51. scanf("%d", &x);
  52. cur->v = x;
  53. cur->prev = now;
  54. cur->next = l;
  55. now->next = cur;
  56. }
  57.  
  58. }
  59. cur = l->next;
  60. for (i = 0; i < n; i++) {
  61. printf("%d ", cur->v);
  62. cur = cur->next;
  63. }
  64. printf("\n");
  65. cur = l->next;
  66. struct Elem *f = l->next;
  67. for (i = 0; i < n; i++) {
  68. cur = f;
  69. f = cur->next;
  70. free(cur);
  71. }
  72. free(l);
  73. }
  74. return 0;
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement