fix errors 1

This commit is contained in:
Daniel Løvbrøtte Olsen 2020-11-25 09:14:23 +01:00
parent c1d0fc9d87
commit 79c639faa5

View File

@ -48,7 +48,7 @@ int main(void) {
int len_number = strlen(number); int len_number = strlen(number);
for (int j = 0; j < len_number; j++) { // loop over chars in the phone number for (int j = 0; j < len_number; j++) { // loop over chars in the phone number
int index = number[j] - '0'; // Go to the node we're testing int index = number[j] - '0'; // Go to the node we're testing
if (pointer->children[index == NULL]) { if (pointer->children[index] == NULL) {
pointer->children[index] = newNode(); pointer->children[index] = newNode();
}; };
pointer = pointer->children[index]; pointer = pointer->children[index];
@ -69,7 +69,7 @@ int main(void) {
printf("FOUND PREFIX IN NUMBER\n"); printf("FOUND PREFIX IN NUMBER\n");
printf("%s and %s", number, number); printf("%s and %s", number, number);
while (pointer->isEnd != true) { // follow the first path you can find while (pointer->isEnd != true) { // follow the first path you can find
for (int k = 0; k < 10; k++) { for (int k = 0; k < 10; k++) {
if( pointer->children[k] != NULL) { if( pointer->children[k] != NULL) {
pointer = pointer->children[k]; pointer = pointer->children[k];
printf("%c", k + '0'); // Print the path as we go printf("%c", k + '0'); // Print the path as we go
@ -83,7 +83,7 @@ int main(void) {
}; };
pointer->isEnd = true; pointer->isEnd = true;
}; };
else if (pointer->isEnd == true) { // if we've already seen a shorter number with this prefix if (pointer->isEnd == true) { // if we've already seen a shorter number with this prefix
printf("Found prefix!\n"); printf("Found prefix!\n");
for (int k = 0; k < j; k++) { for (int k = 0; k < j; k++) {
printf("%c", number[k]); printf("%c", number[k]);