Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #define N 2
- #define SIZE 20
- typedef struct
- {
- char car_type[SIZE];
- int car_number;
- float car_weight;
- }car;
- car carinfo[N];
- car *sortinfo;
- typedef struct
- {
- int parking[N];
- int enterenc[N];
- int top;
- }stack;
- typedef struct
- {
- car carinfo[N];
- stack st;
- }intel_parking;
- intel_parking israel;
- void sortcarinfo(car item[], int n);
- void getinfo(car info[], int n);
- void pushparkstack(car item[], int n);
- int pop(car item2[], int n);
- void main()
- {
- int temp;
- getinfo(carinfo, N);
- sortcarinfo(carinfo, N);
- pushparkstack(carinfo, N-1);
- temp = pop(carinfo, 0);
- }
- void getinfo(car info[], int n)
- {
- int i, len;
- printf("Enter details about the cars that allowed to park:\n");
- for (i = 0; i < n; i++)
- {
- do{
- _flushall();
- printf("Enter type of the car:\n");
- gets(info[i].car_type);
- } while (len = strlen(info[i].car_type) >= 20);
- do{
- _flushall();
- printf("Enter car number (MUST BE A NUMBER ASSEMBLED BY 7 DIGITS):\n");
- scanf("%d", &info[i].car_number);
- } while (info[i].car_number<1000000 || info[i].car_number>9999999);
- do{
- _flushall();
- printf("Enter a car weight (in tons one tons and heigher):\n");
- scanf("%f", &info[i].car_weight);
- } while (info[i].car_weight<1.0);
- }
- }
- void pushparkstack(car item[],int n) {
- israel.st.top++;
- israel.st.parking[israel.st.top] = item[n].car_weight;
- }
- int pop(car item2[], int n) {
- int item;
- item = item2[n].car_number;
- israel.st.parking[israel.st.top];
- israel.st.top--;
- return (item);
- }
- void sortcarinfo(car item[], int n)
- {
- int i, j;
- car *sortinfo = (car *)malloc(1*sizeof(car));
- if (!sortinfo)
- {
- printf("error\n");
- exit(1);
- }
- for (i = 0; i < n; i++)
- {
- for (j = 0; j < n - j - 1; j++)
- {
- if (item[j].car_weight > item[j + 1].car_weight)
- {
- sortinfo[0].car_weight = item[j].car_weight;
- sortinfo[0].car_number = item[j].car_number;
- strcpy(sortinfo[0].car_type,item[j].car_type);
- item[j].car_weight = item[j+1].car_weight;
- item[j].car_number = item[j+1].car_number;
- strcpy(item[j].car_type,item[j+1].car_type);
- item[j+1].car_weight = sortinfo[0].car_weight;
- item[j+1].car_number = sortinfo[0].car_number;
- strcpy(item[j+1].car_type,sortinfo[0].car_type);
- }
- }
- }
- free(sortinfo);
- }
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #define N 2
- #define SIZE 20
- typedef struct
- {
- char car_type[SIZE];
- int car_number;
- float car_weight;
- }car;
- car carinfo[N];
- car *sortinfo;
- typedef struct
- {
- int parking[N];
- int enterenc[N];
- int top;
- }stack;
- typedef struct
- {
- car carinfo[N];
- stack st;
- }intel_parking;
- intel_parking israel;
- void sortcarinfo(car item[], int n);
- void getinfo(car info[], int n);
- void pushparkstack(car item[], int n);
- int pop(car item2[], int n);
- void main()
- {
- int temp;
- getinfo(carinfo, N);
- sortcarinfo(carinfo, N);
- pushparkstack(carinfo, N-1);
- temp = pop(carinfo, 0);
- }
- void getinfo(car info[], int n)
- {
- int i, len;
- printf("Enter details about the cars that allowed to park:\n");
- for (i = 0; i < n; i++)
- {
- do{
- _flushall();
- printf("Enter type of the car:\n");
- gets(info[i].car_type);
- } while (len = strlen(info[i].car_type) >= 20);
- do{
- _flushall();
- printf("Enter car number (MUST BE A NUMBER ASSEMBLED BY 7 DIGITS):\n");
- scanf("%d", &info[i].car_number);
- } while (info[i].car_number<1000000 || info[i].car_number>9999999);
- do{
- _flushall();
- printf("Enter a car weight (in tons one tons and heigher):\n");
- scanf("%f", &info[i].car_weight);
- } while (info[i].car_weight<1.0);
- }
- }
- void pushparkstack(car item[],int n) {
- israel.st.top++;
- israel.st.parking[israel.st.top] = item[n].car_weight;
- }
- int pop(car item2[], int n) {
- int item;
- item = item2[n].car_number;
- israel.st.parking[israel.st.top];
- israel.st.top--;
- return (item);
- }
- void sortcarinfo(car item[], int n)
- {
- int i, j;
- car *sortinfo = (car *)malloc(1*sizeof(car));
- if (!sortinfo)
- {
- printf("error\n");
- exit(1);
- }
- for (i = 0; i < n; i++)
- {
- for (j = 0; j < n - j - 1; j++)
- {
- if (item[j].car_weight > item[j + 1].car_weight)
- {
- sortinfo[0].car_weight = item[j].car_weight;
- sortinfo[0].car_number = item[j].car_number;
- strcpy(sortinfo[0].car_type,item[j].car_type);
- item[j].car_weight = item[j+1].car_weight;
- item[j].car_number = item[j+1].car_number;
- strcpy(item[j].car_type,item[j+1].car_type);
- item[j+1].car_weight = sortinfo[0].car_weight;
- item[j+1].car_number = sortinfo[0].car_number;
- strcpy(item[j+1].car_type,sortinfo[0].car_type);
- }
- }
- }
- free(sortinfo);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement