Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:00,180 --> 00:00:09,510
All right, guys, so here we go to make and implement our SDR compar, or is the RCMP function and
2
00:00:09,510 --> 00:00:10,650
all these function?
3
00:00:10,650 --> 00:00:14,970
Darcey's just the lexicographical comparison.
4
00:00:15,690 --> 00:00:22,750
So we talked about it like we can compare two strings to be part of a dictionary.
5
00:00:22,770 --> 00:00:30,330
OK, and what we want to do is to take these strings, string one and and string two and compare them
6
00:00:30,330 --> 00:00:37,050
and to see which one of them comes first and second and based on the result of who comes first to give
7
00:00:37,050 --> 00:00:38,190
some value.
8
00:00:38,490 --> 00:00:43,470
So in this case, what we do is that we take these two strings.
9
00:00:43,770 --> 00:00:52,620
And if we see that the first string, OK, the first parameter argument comes before, OK, if we take
10
00:00:52,680 --> 00:00:57,720
these string, then it would come before the second string in the deck in the dictionary.
11
00:00:58,380 --> 00:01:05,880
Then the result of the function simply should return us minus one if it's the opposite.
12
00:01:05,880 --> 00:01:11,510
For example, the second string comes before the first one in the dictionary.
13
00:01:11,520 --> 00:01:17,410
So you open up, you see o the first string, the second string comes before the first one.
14
00:01:17,430 --> 00:01:19,440
So the function should return one.
15
00:01:20,010 --> 00:01:27,750
And otherwise if both of the strings are identical then the function should return just zero.
16
00:01:28,530 --> 00:01:35,330
And we've seen that these function may be found and include string H.
17
00:01:35,340 --> 00:01:35,670
Right.
18
00:01:35,670 --> 00:01:39,060
We've seen that these function is actually a part of this library.
19
00:01:39,420 --> 00:01:44,160
And what we want to do is to write this function on our own right to implement it.
20
00:01:44,250 --> 00:01:49,650
So for that, what we are going to do is to create inside of the main function two strings that we will
21
00:01:49,650 --> 00:01:50,230
compare.
22
00:01:50,250 --> 00:01:59,650
So let's make it like charring is the R one, and this string will be like Alpha lets the Alphatech
23
00:01:59,710 --> 00:02:00,170
OK.
24
00:02:00,240 --> 00:02:03,540
And the second string should be like, what?
25
00:02:03,660 --> 00:02:04,550
What should it be?
26
00:02:04,560 --> 00:02:08,920
Let's say like Bob Fatback Alphatech.
27
00:02:08,970 --> 00:02:12,270
OK, so two strings, Alphatech and Balfa taken.
28
00:02:12,270 --> 00:02:18,810
We know that the first string is the other one will come before the second string if we would compare
29
00:02:18,810 --> 00:02:24,860
it and take a look at it and search for it in the dictionary because A comes before B, so we would
30
00:02:24,860 --> 00:02:33,210
have expected some result return based on this action from the RCMP function that we are about to write
31
00:02:33,870 --> 00:02:37,830
in to implement right now, me and you.
32
00:02:38,250 --> 00:02:43,800
So the first thing that we have to do is to define the function structure and the function signature
33
00:02:44,160 --> 00:02:45,720
and basically what should it be?
34
00:02:45,720 --> 00:02:47,700
Should it be made, should it be void?
35
00:02:47,700 --> 00:02:49,260
Should it be a star?
36
00:02:49,260 --> 00:02:52,520
Should it be like, I don't know, should it be maybe integer?
37
00:02:52,540 --> 00:02:53,580
What do you think, guys?
38
00:02:53,880 --> 00:02:58,380
Take a second to think about what should be the the signature of this function.
39
00:02:58,540 --> 00:03:04,350
Pause the video and return to the video once you have some solid answer, whether it will be true or
40
00:03:04,350 --> 00:03:05,730
false, it doesn't matter.
41
00:03:05,740 --> 00:03:08,370
OK, you will learn from these process.
42
00:03:08,370 --> 00:03:14,640
So I'm giving you a couple of seconds, like five, four and just getting guys.
43
00:03:15,240 --> 00:03:18,300
OK, so hopefully you've found some answer.
44
00:03:18,300 --> 00:03:22,590
And what we are going to do is to write the signature so that the signature is very simple.
45
00:03:22,620 --> 00:03:24,780
We can say that because my most.
46
00:03:24,780 --> 00:03:27,300
Oh, so the signature is very simple things.
47
00:03:27,300 --> 00:03:33,930
We know there are only three options that we want to be able to return, whether it's one minus one
48
00:03:35,130 --> 00:03:36,180
or zero.
49
00:03:37,080 --> 00:03:42,090
So an integer type would be pretty much OK for at least one for this option.
50
00:03:42,090 --> 00:03:48,660
So we are going to write end is the RCMP and we are going to receive two strings.
51
00:03:48,720 --> 00:03:55,040
OK, so char pointer is the other one OK, or is your No.
52
00:03:55,050 --> 00:03:57,120
One is also OK is the other one.
53
00:03:57,120 --> 00:04:01,710
And also char pointer is the R two.
54
00:04:02,040 --> 00:04:04,260
OK, so awesome.
55
00:04:04,260 --> 00:04:05,510
So that's the signature.
56
00:04:05,520 --> 00:04:08,010
Let's write the body of the function right now.
57
00:04:08,250 --> 00:04:16,530
So what we know is that if the second string OK comes before, ok, if the second string comes before
58
00:04:16,680 --> 00:04:22,800
the first one in the dictionary then we should return one, otherwise we should return minus one and
59
00:04:22,800 --> 00:04:27,210
if they are identical we should return zero.
60
00:04:27,870 --> 00:04:34,710
So what we are going to do here is that we are going to compare a character by character, the first
61
00:04:34,710 --> 00:04:36,540
string and the second one.
62
00:04:36,900 --> 00:04:39,960
And for that we are going to use something like that.
63
00:04:39,960 --> 00:04:42,570
Let's you and I equals two zero.
64
00:04:42,780 --> 00:04:49,410
And also what I want us to use is some flag, OK, that that will indicate what we had so far.
65
00:04:49,410 --> 00:04:56,220
OK, and I will explain exactly why we're using it, because in a lot of tutorials, the are kind of
66
00:04:56,220 --> 00:04:58,920
missing these part, so.
67
00:04:59,380 --> 00:05:04,960
There you go, so flag equals to zero and one thing that I want to tell you guys is that the solution
68
00:05:04,960 --> 00:05:08,500
that I'm about to share with you is kind of long, OK?
69
00:05:08,530 --> 00:05:15,010
And there is there are different solutions that solve and implement these functions much more efficiently
70
00:05:15,010 --> 00:05:17,710
and with much less lines of code.
71
00:05:18,010 --> 00:05:21,770
But it will be kind of more difficult for me to explain it to you.
72
00:05:21,940 --> 00:05:27,820
So I think this way, where I'm going with you, like, you know, step by step and explaining you all
73
00:05:27,820 --> 00:05:36,160
the details is not the most efficient implementation, but it will be much more understandable for you.
74
00:05:36,370 --> 00:05:39,520
OK, so let us start and write our loop.
75
00:05:39,520 --> 00:05:49,150
So as long as flag equals to zero, as long meaning as long as long as we didn't find any different
76
00:05:50,110 --> 00:05:51,560
different characters.
77
00:05:51,580 --> 00:05:56,700
OK, so as long as we didn't find any different characters between Spring one and spring two, meaning
78
00:05:56,710 --> 00:06:00,540
we are going to characterize it both things is identical.
79
00:06:00,550 --> 00:06:02,290
Second is identical.
80
00:06:02,290 --> 00:06:03,280
Thirty's identical.
81
00:06:03,520 --> 00:06:10,900
As long as we didn't find some flag that says otherwise that the first ring come before and we or the
82
00:06:10,900 --> 00:06:16,540
second comes before, meaning there are two different characters that differ from one another.
83
00:06:17,110 --> 00:06:20,830
So what we are going to do now is to ask a simple condition.
84
00:06:21,100 --> 00:06:26,620
If if string watzman string it's the one, if it's the other one.
85
00:06:26,620 --> 00:06:30,820
Adding Lecci is less than ETR to it index.
86
00:06:31,360 --> 00:06:37,930
OK, so if that's the case, if it's the other one is less of next year or two adding lecci meaning
87
00:06:37,930 --> 00:06:44,200
we found a character that comes at ETR one before is Thierer two.
88
00:06:44,590 --> 00:06:52,600
So if that's the case, what we can say is that flag will be equal to minus one, meaning this is exactly
89
00:06:52,600 --> 00:06:55,150
what we would want to return.
90
00:06:55,150 --> 00:07:01,090
OK, we would like to return these flag of X minus one because it's tier one comes before I start to
91
00:07:01,090 --> 00:07:05,500
and that's how the use the RCMP or regional implementation works.
92
00:07:06,070 --> 00:07:17,240
OK, but if if that's not the case, so let's use else if if there are one OK, sign is greater than
93
00:07:17,410 --> 00:07:20,680
they are to our index to at index theart index.
94
00:07:20,680 --> 00:07:29,660
I mean we still found a character which is not the same as the position of I think Dixy it both of these
95
00:07:29,660 --> 00:07:30,160
strings.
96
00:07:30,160 --> 00:07:35,200
But here is the R two comes before is the other one.
97
00:07:35,200 --> 00:07:39,820
So if that's the case, we know that we should definitely return one.
98
00:07:39,820 --> 00:07:41,410
So flag equals to one.
99
00:07:42,130 --> 00:07:49,330
OK, and once you will return to the condition of these while loop to the next iteration, this condition
100
00:07:49,330 --> 00:07:50,730
will not be true.
101
00:07:50,750 --> 00:07:57,610
OK, so if wild flag equals equals to zero, as long as it equals to zero, we are going to run this
102
00:07:57,610 --> 00:08:03,700
loop and flag will be equal to minus one or one if one character, at least one character was found
103
00:08:03,700 --> 00:08:05,200
and it's not the same.
104
00:08:05,410 --> 00:08:14,350
OK, and last thing that we have to add here is that what will happen if we reached OK, meaning we
105
00:08:14,350 --> 00:08:22,030
have to put here some, you know, like to put here some various that will tell us, OK, guys, you
106
00:08:22,180 --> 00:08:24,370
reached the maximum of string one.
107
00:08:24,370 --> 00:08:33,730
So if ETR SDR one is the one index, i.e. equals two backslash zero at the end, if that's the case,
108
00:08:33,760 --> 00:08:38,200
then basically what we should do is just break and leave this loop alone.
109
00:08:38,800 --> 00:08:45,070
And why is it so useful this if statement and it doesn't it's not part of this condition, it's not
110
00:08:45,070 --> 00:08:52,510
the else of these even L.C, if it's a simple condition that will run no matter what is the result of
111
00:08:52,510 --> 00:08:53,650
the conditions here.
112
00:08:53,870 --> 00:09:00,550
This condition basically tells us this one thing that if you compare, then you didn't find any flags
113
00:09:00,550 --> 00:09:06,190
yet and basically you found that you reached the end of year one.
114
00:09:06,440 --> 00:09:07,900
OK, so you reached the end.
115
00:09:07,900 --> 00:09:17,300
Let's say it was something like so the both strings were like A B and a B, B, OK, so you compared
116
00:09:17,350 --> 00:09:21,720
A and A and it was good B and B and it was good.
117
00:09:21,730 --> 00:09:25,390
And then you compared Bixler zero here at this one string.
118
00:09:25,480 --> 00:09:27,670
That's the other one and B here.
119
00:09:27,670 --> 00:09:34,810
And of course Bixler zero is less than B, so this condition would have been worked, would, would
120
00:09:34,810 --> 00:09:36,300
have worked behind the scenes.
121
00:09:36,730 --> 00:09:44,230
So and here are these will allow you to break out of the loop, OK, with this flag of minus one.
122
00:09:44,230 --> 00:09:48,430
OK, meaning not you will not enter here once again for sure.
123
00:09:48,430 --> 00:09:57,460
And also you will know that the function should be to return minus one because a B will definitely be
124
00:09:57,460 --> 00:09:58,780
in the dictionary.
125
00:09:58,850 --> 00:10:06,590
Before Abby, right, because it's kind of bigger and longer, so that's one of the one of the reasons
126
00:10:06,590 --> 00:10:07,790
why we're using that.
127
00:10:07,940 --> 00:10:12,980
And once you're done, you will simply return of the flag.
128
00:10:13,130 --> 00:10:17,750
OK, so you will return the flag, whether it was minus one, whether it was one.
129
00:10:18,290 --> 00:10:23,990
And also, one thing that we forgot to add here is, of course, of the instrumentation of.
130
00:10:24,470 --> 00:10:29,420
OK, because we every time one to every iteration, one to increment I by one.
131
00:10:29,450 --> 00:10:35,500
So that means we will be able to like to go over the arrays now that the arrays, the strings, OK,
132
00:10:35,510 --> 00:10:37,190
that's just an array of characters.
133
00:10:37,490 --> 00:10:41,820
But still to go over the strings and to find the relevant flag.
134
00:10:42,050 --> 00:10:45,800
So basically we are doing not bad so far.
135
00:10:46,320 --> 00:10:54,230
And one thing last thing that I want to do right now is to not give you a full picture of all the options
136
00:10:54,230 --> 00:10:57,350
that we cover, because here we have a lot of options.
137
00:10:57,560 --> 00:11:03,350
And I want to ask you a simple question and to give you some time to think about it and to come up with
138
00:11:03,350 --> 00:11:07,400
a solution, maybe leave it, leave the comment, leave your answer, answering the comments.
139
00:11:08,810 --> 00:11:15,650
If you don't have a clue, you may also ask for the solution and see what also other people think of
140
00:11:15,650 --> 00:11:15,810
it.
141
00:11:16,070 --> 00:11:18,220
So the question is, what will happen?
142
00:11:18,230 --> 00:11:22,220
The questions, what will happen if both of the strings are the same?
143
00:11:22,490 --> 00:11:24,830
Will they always come to this point?
144
00:11:25,220 --> 00:11:33,530
And also the second question is, should we also be checking ATSDR or tool or gaming if they are to
145
00:11:33,530 --> 00:11:33,650
it?
146
00:11:33,650 --> 00:11:39,780
Indexical equals to equals equals to you Beckler zero, then do this thing or that thing.
147
00:11:40,310 --> 00:11:41,930
So that's also a good question.
148
00:11:42,290 --> 00:11:49,340
And I actually want you to like to think about it and to try to come up with a good solution.
149
00:11:49,460 --> 00:11:57,620
So, yeah, guys, hopefully you found useful this video and the previous exercises and the implementations
150
00:11:57,620 --> 00:12:03,620
of strings functions and as always, keep on practicing.
151
00:12:03,620 --> 00:12:06,080
And I will see you in the next video.
15525
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.