I think it works now
This commit is contained in:
parent
79c639faa5
commit
a5aa29f1ac
@ -37,10 +37,8 @@ int numbers[] = {113, 11354, 77777, 255044};
|
|||||||
|
|
||||||
int main(void) {
|
int main(void) {
|
||||||
struct Node* root = newNode();
|
struct Node* root = newNode();
|
||||||
printf("%p\n", root);
|
|
||||||
|
|
||||||
int n_numbers = sizeof(numbers)/sizeof(int);
|
int n_numbers = sizeof(numbers)/sizeof(int);
|
||||||
|
|
||||||
for (int i = 0; i < n_numbers; i++) { // Go through all the phone numbers in the global list
|
for (int i = 0; i < n_numbers; i++) { // Go through all the phone numbers in the global list
|
||||||
struct Node* pointer = root; // Create a pointer that points to whatever part of the trie we're working on
|
struct Node* pointer = root; // Create a pointer that points to whatever part of the trie we're working on
|
||||||
char number[8 + 1]; // A number has 8 + \0 chars
|
char number[8 + 1]; // A number has 8 + \0 chars
|
||||||
@ -66,7 +64,6 @@ int main(void) {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
if (continues == true) {
|
if (continues == true) {
|
||||||
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++) {
|
||||||
@ -82,14 +79,14 @@ int main(void) {
|
|||||||
return 0; // return true or success or whatever
|
return 0; // return true or success or whatever
|
||||||
};
|
};
|
||||||
pointer->isEnd = true;
|
pointer->isEnd = true;
|
||||||
};
|
}
|
||||||
if (pointer->isEnd == true) { // if we've already seen a shorter number with this prefix
|
else if (pointer->isEnd == true) { // if we've already seen a shorter number with this prefix
|
||||||
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]);
|
||||||
}
|
}
|
||||||
printf("\n");
|
printf(" and %i\n", numbers[i]);
|
||||||
|
return 0;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
with import <nixpkgs> {};
|
with import <nixpkgs> {};
|
||||||
stdenv.mkDerivation {
|
stdenv.mkDerivation {
|
||||||
name = "c-shell";
|
name = "c-shell";
|
||||||
buildInputs = [ gcc gnumake ];
|
buildInputs = [ gcc gnumake gdb ];
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user