Advertisement
mcgizmo

Untitled

Dec 5th, 2016
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.02 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3. #include<string.h>
  4.  
  5. #define N 4
  6. #define SIZE 20
  7. #define ID 7
  8.  
  9.  
  10. typedef struct
  11. {
  12. char type[SIZE];
  13. int number[ID];
  14. float weight;
  15. }car;
  16.  
  17. car carInfo[N];
  18. car *sorting;
  19.  
  20. struct stack /* Structure definition for stack */
  21. {
  22. int *parking;
  23. int MAXSIZE;
  24. int top;
  25. };
  26. typedef struct stack STACK;
  27. STACK st;
  28.  
  29. void CreateStack(STACK *p, int MAXSIZE);
  30. void GetInfo(car Info[], int a);
  31. void SortCar(car Info[], int a);
  32. void pushCarParking(car Info[], int a);
  33.  
  34.  
  35. void main()
  36. {
  37. int i;
  38. CreateStack(&st, N);
  39. GetInfo(carInfo, N);
  40. SortCar(carInfo, N);
  41. printf("please choce a parking slot for car:\n");
  42. for (i = N - 1; i >= 0; i--)
  43. {
  44. pushCarParking(carInfo, i);
  45. }
  46.  
  47.  
  48. for (i = 0; i < N; i++)
  49. printf("%d", &carInfo[i].number);
  50. PushPopCars(carInfo, N);
  51.  
  52. }
  53.  
  54.  
  55. void GetInfo(car Data[], int a)
  56. {
  57. int i, length;
  58. printf("Enter details about the cars that allowed to park:\n");
  59. for (i = 0; i < a; i++)
  60. {
  61. do{
  62. _flushall();
  63. printf("Enter type of the car:\n");
  64. gets(Data[i].type);
  65.  
  66. } while (length = strlen(Data[i].type) >= 20);
  67.  
  68. do{
  69. _flushall();
  70. printf("Enter car number (MUST BE A NUMBER ASSEMBLED BY 7 DIGITS):\n");
  71. scanf("%d", &Data[i].number);
  72.  
  73. } while (Data[i].number < 1000000 || Data[i].number>9999999);
  74.  
  75. do{
  76. _flushall();
  77. printf("Enter a car weight (in tons one tons and heigher):\n");
  78. scanf("%f", &Data[i].weight);
  79.  
  80. } while (Data[i].weight < 1.0);
  81. }
  82. }
  83.  
  84. void CreateStack(STACK *p, int MAXSIZE)
  85. {
  86. p->MAXSIZE;
  87. p->parking = (car*)malloc(MAXSIZE*sizeof(car));
  88. p->top = -1;
  89.  
  90. }
  91.  
  92. void pushCarParking(car Info[], int a)
  93. {
  94. st.top++;
  95. st.parking[st.top] = Info[a];
  96.  
  97. }
  98.  
  99. void SortCar(car Info[], int a)
  100. {
  101. int i, j, temp;
  102. for (i = 0; i <= a - 1; i++)
  103. {
  104. for (j = 0; j <= a - i; j++)
  105. {
  106. if (Info[j - 1].weight >= Info[j].weight)
  107. {
  108. temp = Info[j - 1].weight;
  109. Info[j - 1].weight = Info[j].weight;
  110. Info[j].weight = temp;
  111. }
  112. }
  113. }
  114. }
  115.  
  116. int PushPopCars(car Info[], int a)
  117. {
  118.  
  119. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement