| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- #include <stdio.h>
- #include <stdlib.h>
- #include <time.h>
- #include "packing.h"
- int main(int argc, char **argv){
- //check arguments
- if (argc != 3){
- printf("usage: ./proj3 <input_file> <output_file>\n");
- return EXIT_FAILURE;
- }
-
- // read data
- int numnodes = 0;
- int numboxes = 0;
- Node *array = load_file(argv[1], &numnodes, &numboxes);
- if(array == NULL){ // check for error
- printf("File read error.");
- return EXIT_FAILURE;
- }
-
- // create tree
- Node *root = set_pointers(array, numnodes);
-
- // pack
- clock_t packingClock = clock(); // track packing time
- double packingTime = 0;
- set_values(root);
- packingClock = clock() - packingClock; // time after packing
- packingTime = packingTime + ((double) packingClock) / CLOCKS_PER_SEC;
-
- // print to stdout
- printf("Preorder: ");
- print_node_numbers_preorder(root);
- printf("\n\n");
- printf("Inorder: ");
- print_node_numbers_inorder(root);
- printf("\n\n");
- printf("Postorder: ");
- print_node_numbers_postorder(root);
- printf("\n\n");
-
- printf("Width: %le\n", root->width);
- printf("Height: %le\n", root->height);
- printf("\n");
-
- printf("X-coordinate: %le\n", array[numboxes - 1].xcord);
- printf("Y-coordinate: %le\n", array[numboxes - 1].ycord);
- printf("\n");
-
- printf("Elapsed time: %le\n", packingTime);
- printf("\n");
-
- // save boxes
- save_boxes(argv[2], array, numboxes);
-
- // clean up
- free(array); // free memory
- return EXIT_SUCCESS; // exit
- }
|