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 4
- #define SIZE 20
- #define ID 7
- typedef struct
- {
- char type[SIZE];
- int number[ID];
- float weight;
- }car;
- car carInfo[N];
- car *sorting;
- struct stack /* Structure definition for stack */
- {
- int *parking;
- int MAXSIZE;
- int top;
- };
- typedef struct stack STACK;
- STACK st;
- void CreateStack(STACK *p, int MAXSIZE);
- void GetInfo(car Info[], int a);
- void SortCar(car Info[], int a);
- void pushCarParking(car Info[], int a);
- void main()
- {
- int i;
- CreateStack(&st, N);
- GetInfo(carInfo, N);
- SortCar(carInfo, N);
- printf("please choce a parking slot for car:\n");
- for (i = N - 1; i >= 0; i--)
- {
- pushCarParking(carInfo, i);
- }
- for (i = 0; i < N; i++)
- printf("%d", &carInfo[i].number);
- PushPopCars(carInfo, N);
- }
- void GetInfo(car Data[], int a)
- {
- int i, length;
- printf("Enter details about the cars that allowed to park:\n");
- for (i = 0; i < a; i++)
- {
- do{
- _flushall();
- printf("Enter type of the car:\n");
- gets(Data[i].type);
- } while (length = strlen(Data[i].type) >= 20);
- do{
- _flushall();
- printf("Enter car number (MUST BE A NUMBER ASSEMBLED BY 7 DIGITS):\n");
- scanf("%d", &Data[i].number);
- } while (Data[i].number < 1000000 || Data[i].number>9999999);
- do{
- _flushall();
- printf("Enter a car weight (in tons one tons and heigher):\n");
- scanf("%f", &Data[i].weight);
- } while (Data[i].weight < 1.0);
- }
- }
- void CreateStack(STACK *p, int MAXSIZE)
- {
- p->MAXSIZE;
- p->parking = (car*)malloc(MAXSIZE*sizeof(car));
- p->top = -1;
- }
- void pushCarParking(car Info[], int a)
- {
- st.top++;
- st.parking[st.top] = Info[a];
- }
- void SortCar(car Info[], int a)
- {
- int i, j, temp;
- for (i = 0; i <= a - 1; i++)
- {
- for (j = 0; j <= a - i; j++)
- {
- if (Info[j - 1].weight >= Info[j].weight)
- {
- temp = Info[j - 1].weight;
- Info[j - 1].weight = Info[j].weight;
- Info[j].weight = temp;
- }
- }
- }
- }
- int PushPopCars(car Info[], int a)
- {
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement