Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- struct Cuboid
- {
- char name;
- double x;
- double y;
- double z;
- struct Cuboid *next;
- };
- void loadCuboidData(struct Cuboid **pointer)
- {
- (*pointer)->next = NULL;
- printf("\n\n\n\n\n\n\n\nWprowadz identyfikator pudelka (1 znak): ");
- scanf(" %c", &((*pointer)->name));
- printf("Wprowadz wymiar X: ");
- scanf("%lf", &((*pointer)->x));
- printf("Wprowadz wymiar Y: ");
- scanf("%lf", &((*pointer)->y));
- printf("Wprowadz wymiar Z: ");
- scanf("%lf", &((*pointer)->z));
- }
- void addCuboid(struct Cuboid **headPointer)
- {
- struct Cuboid *pointer;
- pointer = *headPointer;
- if (pointer == NULL)
- {
- pointer = (struct Cuboid*)malloc(sizeof(struct Cuboid));
- loadCuboidData(&pointer);
- *headPointer = pointer;
- }
- else
- {
- while (pointer->next != NULL)
- {
- pointer = pointer->next;
- }
- pointer->next = (struct Cuboid*)malloc(sizeof(struct Cuboid));
- pointer = pointer->next;
- loadCuboidData(&pointer);
- }
- }
- void loadCuboids(struct Cuboid **headPointer)
- {
- int choose;
- printf("1. Dodaj prostopadloscian.\n");
- printf("2. Zakoncz dodawanie.\n");
- scanf("%d", &choose);
- while(choose == 1)
- {
- addCuboid(headPointer);
- printf("1. Dodaj prostopadloscian.\n");
- printf("2. Zakoncz dodawanie.\n");
- scanf("%d", &choose);
- }
- }
- int listSize(struct Cuboid *head)
- {
- int sizeOfList;
- sizeOfList = 0;
- if (head != NULL)
- {
- sizeOfList = 1;
- while (head->next != NULL)
- {
- head = head->next;
- sizeOfList++;
- }
- }
- return sizeOfList;
- }
- void checkCouboids(struct Cuboid *head, int ***boxSizesArray)
- {
- int sizeOfList, i, j;
- struct Cuboid *pointer, *pointer2;
- sizeOfList = listSize(head);
- *boxSizesArray = (int**)malloc(sizeof(int*) * (sizeOfList - 1));
- j = sizeOfList - 1;
- for (i = 0; i < (sizeOfList - 1); i++)
- {
- (*boxSizesArray)[i] = (int*)malloc(sizeof(int)*j);
- j--;
- }
- pointer = head;
- pointer2 = head;
- for (i = 0; i < (sizeOfList - 1); i++)
- {
- for(j = 0; j < (sizeOfList - 1 - i); j++)
- {
- pointer2 = pointer2->next;
- if ( (pointer->x > pointer2->x) && (pointer->y > pointer2->y) && (pointer->z > pointer2->z) )
- {
- (*boxSizesArray)[i][j] = 1;
- }
- else if ( (pointer->x < pointer2->x) && (pointer->y < pointer2->y) && (pointer->z < pointer2->z) )
- {
- (*boxSizesArray)[i][j] = -1;
- }
- else
- {
- (*boxSizesArray)[i][j] = 0;
- }
- }
- pointer = pointer->next;
- pointer2 = pointer;
- }
- }
- int main()
- {
- struct Cuboid *head;
- int **boxSizesArray;
- int sizeOfList, i, j;
- head = NULL;
- loadCuboids(&head);
- checkCouboids(head, &boxSizesArray);
- sizeOfList = listSize(head);
- for (i = 0; i < (sizeOfList - 1); i++)
- {
- for (j = 0; j < (sizeOfList - 1 - i); j++)
- {
- if (boxSizesArray[i][j] == 1)
- {
- printf("> ");
- }
- else if (boxSizesArray[i][j] == -1)
- {
- printf("< ");
- }
- else
- {
- printf("~ ");
- }
- }
- printf("\n");
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement