Advertisement
palmerstone

Untitled

Sep 18th, 2011
506
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.62 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <math.h>
  4. #include <string.h>
  5. #include <ctype.h>
  6.  
  7. struct node
  8. {
  9. node *prev;
  10. int x;
  11. node *next;
  12. };
  13.  
  14. node *ptr = 0, *ptr2 = 0, *ptr3 = 0, *ptr4 = 0, *ptr5 = 0, *ptr6 = 0, *ptr7 = 0;
  15.  
  16. int main()
  17. {
  18. int t, i, j, k, l, a, b, c, d, y, z, n;
  19. char ch;
  20.  
  21. ptr = (node *)malloc(sizeof(node));
  22. ptr->x = -1919191;
  23. ptr->prev = 0;
  24. ptr->next = 0;
  25. ptr2 = ptr;
  26. ptr3 = ptr;
  27. ptr4 = ptr;
  28.  
  29. scanf("%d", &t);
  30. getchar();
  31. for (i = 1; i <= t; i++)
  32. {
  33. ptr2 = ptr4;
  34. ch = getchar();
  35. getchar();
  36. scanf("%d", &n);
  37. getchar();
  38.  
  39. if (ch == 105)
  40. {
  41. printf("List: ");
  42. ptr->next = (node *)malloc(sizeof(node));
  43. ptr = ptr->next;
  44. ptr->x = n;
  45. ptr->next = 0;
  46. ptr->prev = ptr3;
  47. ptr3 = ptr;
  48.  
  49. ptr2 = ptr;
  50. for (; ;)
  51. {
  52. b = ptr2->x;
  53. ptr7 = ptr2->prev;
  54. if (ptr7->x == -1919191) break;
  55. a = ptr7->x;
  56. if (a > b)
  57. {
  58. ptr7->x = b;
  59. ptr2->x = a;
  60. }
  61. ptr2 = ptr2->prev;
  62. }
  63.  
  64. ptr2 = ptr4;
  65. while(true)
  66. {
  67. ptr2 = ptr2->next;
  68. printf("%d ", ptr2->x);
  69. if (ptr2->next == 0) break;
  70. }
  71. putchar(10);
  72. }
  73.  
  74. if (ch == 100)
  75. {
  76. d = 0;
  77. for (; ;)
  78. {
  79. ptr2 = ptr2->next;
  80. if (ptr2->x == n)
  81. {
  82. printf("%d Deleted\n", n);
  83. ptr5 = ptr2->prev;
  84. ptr6 = ptr5;
  85. ptr5->next = ptr2->next;
  86. ptr5 = ptr5->next;
  87. ptr5->prev = ptr6;
  88. d = 1;
  89. break;
  90. }
  91. if (ptr2->next == 0) break;
  92. }
  93. if (d == 0) printf("%d Not Found\n", n);
  94. }
  95.  
  96. if (ch == 115)
  97. {
  98. ptr2 = ptr4, d = 0;
  99. for (; ;)
  100. {
  101. ptr2 = ptr2->next;
  102. if (ptr2->x == n)
  103. {
  104. printf("%d Found\n", n);
  105. d = 1;
  106. break;
  107. }
  108. if (ptr2->next == 0) break;
  109. }
  110. if (d == 0) printf("%d Not Found\n", n);
  111. }
  112. }
  113. return 0x0;
  114. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement