Advertisement
Void-voiD

Untitled

Dec 22nd, 2018
196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.55 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. cur = l->next;
  59. for (i = 0; i < n; i++) {
  60. printf("%d ", cur->v);
  61. cur = cur->next;
  62. }
  63. printf("\n");
  64. free(l);
  65. free(cur);
  66. free(now);
  67. }
  68. return 0;
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement