Afrikaans
Akan
Albanian
Amharic
Arabic
Armenian
Azerbaijani
Basque
Belarusian
Bemba
Bengali
Bihari
Bosnian
Breton
Bulgarian
Cambodian
Catalan
Cebuano
Cherokee
Chichewa
Chinese (Simplified)
Chinese (Traditional)
Corsican
Croatian
Czech
Danish
Dutch
English
Esperanto
Estonian
Ewe
Faroese
Filipino
Finnish
French
Frisian
Ga
Galician
Georgian
German
Greek
Guarani
Gujarati
Haitian Creole
Hausa
Hawaiian
Hebrew
Hindi
Hmong
Icelandic
Igbo
Indonesian
Interlingua
Irish
Italian
Japanese
Javanese
Kannada
Kazakh
Kinyarwanda
Kirundi
Kongo
Korean
Krio (Sierra Leone)
Kurdish
Kurdish (Soranî)
Kyrgyz
Laothian
Latin
Latvian
Lingala
Lithuanian
Lozi
Luganda
Luo
Luxembourgish
Macedonian
Malagasy
Malay
Malayalam
Maltese
Maori
Marathi
Mauritian Creole
Moldavian
Mongolian
Myanmar (Burmese)
Montenegrin
Nepali
Nigerian Pidgin
Northern Sotho
Norwegian
Norwegian (Nynorsk)
Occitan
Oriya
Oromo
Pashto
Persian
Polish
Portuguese (Brazil)
Portuguese (Portugal)
Punjabi
Quechua
Romanian
Romansh
Runyakitara
Russian
Samoan
Scots Gaelic
Serbian
Serbo-Croatian
Sesotho
Setswana
Seychellois Creole
Shona
Sindhi
Sinhalese
Slovak
Slovenian
Somali
Spanish
Spanish (Latin American)
Sundanese
Swahili
Swedish
Tajik
Tamil
Tatar
Telugu
Thai
Tigrinya
Tonga
Tshiluba
Tumbuka
Turkish
Turkmen
Twi
Uighur
Ukrainian
Urdu
Uzbek
Vietnamese
Welsh
Wolof
Xhosa
Yiddish
Yoruba
Zulu
All right, guys, so here we go to make and implement our SDR compar, or is the RCMP function and
all these function?
Darcey's just the lexicographical comparison.
So we talked about it like we can compare two strings to be part of a dictionary.
OK, and what we want to do is to take these strings, string one and and string two and compare them
and to see which one of them comes first and second and based on the result of who comes first to give
some value.
So in this case, what we do is that we take these two strings.
And if we see that the first string, OK, the first parameter argument comes before, OK, if we take
these string, then it would come before the second string in the deck in the dictionary.
Then the result of the function simply should return us minus one if it's the opposite.
For example, the second string comes before the first one in the dictionary.
So you open up, you see o the first string, the second string comes before the first one.
So the function should return one.
And otherwise if both of the strings are identical then the function should return just zero.
And we've seen that these function may be found and include string H.
Right.
We've seen that these function is actually a part of this library.
And what we want to do is to write this function on our own right to implement it.
So for that, what we are going to do is to create inside of the main function two strings that we will
compare.
So let's make it like charring is the R one, and this string will be like Alpha lets the Alphatech
OK.
And the second string should be like, what?
What should it be?
Let's say like Bob Fatback Alphatech.
OK, so two strings, Alphatech and Balfa taken.
We know that the first string is the other one will come before the second string if we would compare
it and take a look at it and search for it in the dictionary because A comes before B, so we would
have expected some result return based on this action from the RCMP function that we are about to write
in to implement right now, me and you.
So the first thing that we have to do is to define the function structure and the function signature
and basically what should it be?
Should it be made, should it be void?
Should it be a star?
Should it be like, I don't know, should it be maybe integer?
What do you think, guys?
Take a second to think about what should be the the signature of this function.
Pause the video and return to the video once you have some solid answer, whether it will be true or
false, it doesn't matter.
OK, you will learn from these process.
So I'm giving you a couple of seconds, like five, four and just getting guys.
OK, so hopefully you've found some answer.
And what we are going to do is to write the signature so that the signature is very simple.
We can say that because my most.
Oh, so the signature is very simple things.
We know there are only three options that we want to be able to return, whether it's one minus one
or zero.
So an integer type would be pretty much OK for at least one for this option.
So we are going to write end is the RCMP and we are going to receive two strings.
OK, so char pointer is the other one OK, or is your No.
One is also OK is the other one.
And also char pointer is the R two.
OK, so awesome.
So that's the signature.
Let's write the body of the function right now.
So what we know is that if the second string OK comes before, ok, if the second string comes before
the first one in the dictionary then we should return one, otherwise we should return minus one and
if they are identical we should return zero.
So what we are going to do here is that we are going to compare a character by character, the first
string and the second one.
And for that we are going to use something like that.
Let's you and I equals two zero.
And also what I want us to use is some flag, OK, that that will indicate what we had so far.
OK, and I will explain exactly why we're using it, because in a lot of tutorials, the are kind of
missing these part, so.
There you go, so flag equals to zero and one thing that I want to tell you guys is that the solution
that I'm about to share with you is kind of long, OK?
And there is there are different solutions that solve and implement these functions much more efficiently
and with much less lines of code.
But it will be kind of more difficult for me to explain it to you.
So I think this way, where I'm going with you, like, you know, step by step and explaining you all
the details is not the most efficient implementation, but it will be much more understandable for you.
OK, so let us start and write our loop.
So as long as flag equals to zero, as long meaning as long as long as we didn't find any different
different characters.
OK, so as long as we didn't find any different characters between Spring one and spring two, meaning
we are going to characterize it both things is identical.
Second is identical.
Thirty's identical.
As long as we didn't find some flag that says otherwise that the first ring come before and we or the
second comes before, meaning there are two different characters that differ from one another.
So what we are going to do now is to ask a simple condition.
If if string watzman string it's the one, if it's the other one.
Adding Lecci is less than ETR to it index.
OK, so if that's the case, if it's the other one is less of next year or two adding lecci meaning
we found a character that comes at ETR one before is Thierer two.
So if that's the case, what we can say is that flag will be equal to minus one, meaning this is exactly
what we would want to return.
OK, we would like to return these flag of X minus one because it's tier one comes before I start to
and that's how the use the RCMP or regional implementation works.
OK, but if if that's not the case, so let's use else if if there are one OK, sign is greater than
they are to our index to at index theart index.
I mean we still found a character which is not the same as the position of I think Dixy it both of these
strings.
But here is the R two comes before is the other one.
So if that's the case, we know that we should definitely return one.
So flag equals to one.
OK, and once you will return to the condition of these while loop to the next iteration, this condition
will not be true.
OK, so if wild flag equals equals to zero, as long as it equals to zero, we are going to run this
loop and flag will be equal to minus one or one if one character, at least one character was found
and it's not the same.
OK, and last thing that we have to add here is that what will happen if we reached OK, meaning we
have to put here some, you know, like to put here some various that will tell us, OK, guys, you
reached the maximum of string one.
So if ETR SDR one is the one index, i.e. equals two backslash zero at the end, if that's the case,
then basically what we should do is just break and leave this loop alone.
And why is it so useful this if statement and it doesn't it's not part of this condition, it's not
the else of these even L.C, if it's a simple condition that will run no matter what is the result of
the conditions here.
This condition basically tells us this one thing that if you compare, then you didn't find any flags
yet and basically you found that you reached the end of year one.
OK, so you reached the end.
Let's say it was something like so the both strings were like A B and a B, B, OK, so you compared
A and A and it was good B and B and it was good.
And then you compared Bixler zero here at this one string.
That's the other one and B here.
And of course Bixler zero is less than B, so this condition would have been worked, would, would
have worked behind the scenes.
So and here are these will allow you to break out of the loop, OK, with this flag of minus one.
OK, meaning not you will not enter here once again for sure.
And also you will know that the function should be to return minus one because a B will definitely be
in the dictionary.
Before Abby, right, because it's kind of bigger and longer, so that's one of the one of the reasons
why we're using that.
And once you're done, you will simply return of the flag.
OK, so you will return the flag, whether it was minus one, whether it was one.
And also, one thing that we forgot to add here is, of course, of the instrumentation of.
OK, because we every time one to every iteration, one to increment I by one.
So that means we will be able to like to go over the arrays now that the arrays, the strings, OK,
that's just an array of characters.
But still to go over the strings and to find the relevant flag.
So basically we are doing not bad so far.
And one thing last thing that I want to do right now is to not give you a full picture of all the options
that we cover, because here we have a lot of options.
And I want to ask you a simple question and to give you some time to think about it and to come up with
a solution, maybe leave it, leave the comment, leave your answer, answering the comments.
If you don't have a clue, you may also ask for the solution and see what also other people think of
it.
So the question is, what will happen?
The questions, what will happen if both of the strings are the same?
Will they always come to this point?
And also the second question is, should we also be checking ATSDR or tool or gaming if they are to
it?
Indexical equals to equals equals to you Beckler zero, then do this thing or that thing.
So that's also a good question.
And I actually want you to like to think about it and to try to come up with a good solution.
So, yeah, guys, hopefully you found useful this video and the previous exercises and the implementations
of strings functions and as always, keep on practicing.
And I will see you in the next video.
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.