Advertisement
Void-voiD

Untitled

Dec 22nd, 2018
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.54 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;
  12. x.v = -777777777;
  13. x.prev = &x;
  14. x.next = &x;
  15. return x;
  16. }
  17.  
  18. void InsertSort(struct Elem *data, int n)
  19. {
  20. struct Elem that, this;
  21. int i = 1, j;
  22. while (i < n) {
  23.  
  24. i++;
  25. }
  26. }
  27.  
  28. int main()
  29. {
  30. int n, i, x, j;
  31. scanf("%d\n", &n);
  32. if (n == 1) {
  33. scanf("%d", &i);
  34. printf("%d\n", i);
  35. }
  36. else {
  37. struct Elem l = InitDoubleLinkedList();
  38. struct Elem cur, now;
  39. for (i = 0; i < n; i++) {
  40. if (i == 0) {
  41. scanf("%d ", &x);
  42. cur.v = x;
  43. cur.prev = &l;
  44. l.next = &cur;
  45. }
  46. if (i < n - 1 && i != 0) {
  47. scanf("%d ", &x);
  48. now = l;
  49. for (j = 0; j <= i; j++) now = *now.next;
  50. cur.v = x;
  51. cur.prev = &now;
  52. now.next = &cur;
  53. }
  54. if (i == n - 1) {
  55. scanf("%d", &x);
  56. now = l;
  57. for (j = 0; j <= i; j++) now = *now.next;
  58. cur.v = x;
  59. cur.prev = &now;
  60. cur.next = &l;
  61. now.next = &cur;
  62. }
  63. }
  64. cur = *l.next;
  65. for (i = 0; i < n; i++) {
  66. printf("%d ", cur.v);
  67. cur = *cur.next;
  68. }
  69. printf("\n");
  70. }
  71. return 0;
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement