Advertisement
Guest User

Untitled

a guest
Feb 18th, 2020
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.49 KB | None | 0 0
  1. #define _CRT_SECURE_NO_WARNINGS
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <locale.h>
  5.  
  6.  
  7. typedef struct Flat
  8. {
  9. int floor, countRoom, Square;
  10. struct {
  11. char district[20];
  12. char street[20];
  13. }Adress;
  14. struct Flat* next;
  15. } Flat;
  16.  
  17.  
  18. Flat *First, *Last, *el;
  19.  
  20. void push(int inf, int max)
  21. {
  22. int tmp;
  23.  
  24. while(1)
  25. {
  26. struct Flat* el;
  27. el = (struct Flat*)malloc(sizeof(struct Flat));
  28. if (el == NULL)
  29. {
  30. printf("Не удалось выделить память под элемент списка.\n");
  31. return;
  32. }
  33. el->next = NULL;
  34.  
  35. if (First == NULL)
  36. First = Last = el;
  37. else
  38. {
  39. Last->next = el;
  40. Last = Last->next;
  41. }
  42. printf("Введите данные квартиры: \n");
  43. printf("Введите количество комнат: ");
  44. scanf("%d", &el->countRoom);
  45. printf("\nВведите площадь комнаты: ");
  46. scanf("%d", &el->Square);
  47. printf("\nВведите этаж: ");
  48. scanf("%d", &el->floor);
  49. printf("\nВведите район: ");
  50. scanf("%s", &(el->Adress.district));
  51. printf("\nВведите район: ");
  52. scanf("%s", &(el->Adress.street));
  53.  
  54. }
  55.  
  56. int main(void)
  57. {
  58. setlocale(LC_ALL, "Russian");
  59. First = Last = NULL;
  60.  
  61. printf("Введите элементы списка (окончание ввода -- любой символ, кроме цифры):\n");
  62. while (scanf("%d", &inf) != 0)
  63. {
  64. push(inf,max);
  65. k++;
  66. }
  67. for (el = First; el != Last; el = el->next)
  68. if (el->info > max)
  69. max= el->info;
  70.  
  71. el = First;
  72. while (el != NULL)
  73. {
  74. tmp = First;
  75. if (el->info == max)
  76. {
  77. if (el == First)
  78. {
  79. First = el->next;
  80. el = el->next;
  81. }
  82. else
  83. {
  84. while (tmp->next != el)
  85. tmp = tmp->next;
  86. tmp->next = el->next;
  87. el=el->next;
  88. }
  89. }
  90. else
  91. el = el->next;
  92. }
  93.  
  94. printf("\n");
  95.  
  96. for (el = First; el != NULL; el = el->next)
  97. {
  98. printf("%d ", el->info);
  99. }
  100.  
  101. for (el = First; el != NULL;)
  102. {
  103. tmp = el;
  104. el = el->next;
  105. free(tmp);
  106. }
  107. return 0;
  108. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement