// dial Picking // dial_picking.c // // This program was written by YOUR NAME (z5555555) // on ??/??/?? // // A program used to find the quickest way to break the mathematician's lock! #include #include #define FALSE 0 #define TRUE 1 enum direction { NONE, RIGHT, LEFT }; struct dial { struct number *start; }; struct number { int value; struct number *right; struct number *left; }; // TODO: add any of your own structs void initalise_dial(struct dial *dial); void free_dial(struct dial *dial); void pick_lock(struct dial *dial_1, struct dial *dial_2); // TODO: add any of your own function prototypes // DO NOT CHANGE THIS MAIN FUNCTION // main function that runs code int main(void) { struct dial *dial_1 = malloc(sizeof(struct dial)); struct dial *dial_2 = malloc(sizeof(struct dial)); initalise_dial(dial_1); initalise_dial(dial_2); pick_lock(dial_1, dial_2); free_dial(dial_1); free_dial(dial_2); return 0; } //function that prints out the correct solution to the lock void pick_lock(struct dial *dial_1, struct dial *dial_2) { //TODO: complete code } // DO NOT CHANGE THIS FUNCTION //initalises a dial void initalise_dial(struct dial *dial) { int num_numbers; printf("How many numbers in the dial: "); scanf("%d", &num_numbers); struct number *current = malloc(sizeof(struct number)); int value; scanf("%d", &value); current->value = value; int i = 1; //add to start of dial dial->start = current; while (i < num_numbers) { //assign value to new node struct number *previous = current; current = malloc(sizeof(struct number)); scanf("%d", &value); current->value = value; //attach to previous previous->right = current; current->left = previous; i++; } current->right = dial->start; dial->start->left = current; } // DO NOT CHANGE THIS FUNCTION //frees all the data associated with a dial (and the dial itself) void free_dial(struct dial *dial) { struct number *start = dial->start; struct number *current = start; struct number *to_delete = current; current = current->right; free(to_delete); while (current != start) { to_delete = current; current = current->right; free(to_delete); } free(dial); }