-
Notifications
You must be signed in to change notification settings - Fork 16
add main.c update csting.h #18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
| int64_t LevenstheinRecursive(TString s1, TString s2, int64_t len1, int64_t len2) { | ||
| int64_t a, b, c; | ||
| if (len1 == 0) { | ||
| return len2; | ||
| } | ||
| if (len2 == 0) { | ||
| return len1; | ||
| } | ||
| if (s1.data[len1 - 1] == s2.data[len2 - 1]) { | ||
| return LevenstheinRecursive(s1, s2, len1 - 1, len2 - 1); | ||
| } | ||
| a = LevenstheinRecursive(s1, s2, len1 - 1, len2 - 1); | ||
| b = LevenstheinRecursive(s1, s2, len1, len2 - 1); | ||
| c = LevenstheinRecursive(s1, s2, len1 - 1, len2); | ||
|
|
||
| if (a > b) a = b; | ||
| if (a > c) a = c; | ||
| return a + 1; | ||
| } | ||
|
|
||
| int64_t stringLevenstheinDistance(TString s1, TString s2) { | ||
| int64_t len1 = (int64_t)stringLen(s1); | ||
| int64_t len2 = (int64_t)stringLen(s2); | ||
| int64_t res = LevenstheinRecursive(s1, s2, len1, len2); | ||
| return res; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what is it? Place it into cstring.h to other funtions
| int64_t len1 = (int64_t)stringLen(s1); | ||
| int64_t len2 = (int64_t)stringLen(s2); | ||
| int64_t res = LevenstheinRecursive(s1, s2, len1, len2); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you really need int64_t? Use size_t instead
| TString myString1 = stringInitWithCharArr("hello world"); | ||
| TString myString2 = stringInitWithCharArr("hello 112312ld"); | ||
| int64_t res = stringLevenstheinDistance(myString1, myString2); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move test to testfile.
Add more cases: empty string, equal strings and so on
| #include "cstring.h" | ||
| #include <string.h> | ||
|
|
||
| int64_t LevenstheinRecursive(TString s1, TString s2, int64_t len1, int64_t len2) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code is very clear, nice!
| @@ -1,944 +1,945 @@ | |||
| #ifndef CSTRING_LIB | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is wrong! The entire file has been deleted and added back, some kind of error. It is necessary that only the really modified parts of the code are highlighted. Please fix it
in main.c there is a realization of levensthtein distance functrion;
in updated cstring.h there is a new func called stringLevenstheinDistance