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,000
So additional question in our programming course regarding linked lists, I hope you are on right so
2
00:00:09,000 --> 00:00:09,420
far.
3
00:00:09,480 --> 00:00:14,730
So this question is very similar to you exercise the previous exercise.
4
00:00:14,740 --> 00:00:17,140
So we will go over it really quickly.
5
00:00:17,340 --> 00:00:23,970
So what do we have to do is to write a function that receives a linked receives a linked list and some
6
00:00:23,970 --> 00:00:25,540
integer number, OK?
7
00:00:26,100 --> 00:00:30,660
And all the function should do is simply to return the number.
8
00:00:30,720 --> 00:00:32,550
OK, let's modify this part.
9
00:00:32,850 --> 00:00:35,260
Return the number.
10
00:00:35,310 --> 00:00:43,740
OK, the number of occurrences of these events number in the list.
11
00:00:43,920 --> 00:00:51,960
OK, so we receive a linked list and we receive a number and we eat to rate over all the nodes of these
12
00:00:51,960 --> 00:00:55,490
linked list and then we count how many times.
13
00:00:56,460 --> 00:01:03,960
And we we we've even if we have encountered in the nodes that have these integer number.
14
00:01:04,160 --> 00:01:07,530
OK, so let's start writing down the function.
15
00:01:07,740 --> 00:01:13,170
And what we can say is that the function is going to be probably of an integer type.
16
00:01:13,170 --> 00:01:19,520
Right, because we use it to count something to count the number of nodes having these number.
17
00:01:19,530 --> 00:01:20,910
OK, and it's very simple.
18
00:01:20,910 --> 00:01:31,500
So ain't, let's say, total total number appearances, appearances, even say it in list.
19
00:01:31,560 --> 00:01:38,270
OK, so these function will receive the header and also it will receive a number.
20
00:01:38,290 --> 00:01:40,560
So it no num no.
21
00:01:40,650 --> 00:01:47,240
You know, what we are going to do here is to create a count variable just like previously in council
22
00:01:47,250 --> 00:01:54,660
or in count equals to zero node pointer current and let's say tampoe equals to had.
23
00:01:55,170 --> 00:02:01,740
You know what we are going to do is as long as we haven't reached the end of the linked list, meaning
24
00:02:01,860 --> 00:02:05,090
we haven't reached the last node.
25
00:02:05,400 --> 00:02:13,320
So while Tambe next does not equals two does not equal to null.
26
00:02:13,680 --> 00:02:21,330
So as long as that's the case, we will check if temp data equals to.
27
00:02:22,080 --> 00:02:31,030
And if that's the case, we will simply use count plus plus meaning we found a node that has as its
28
00:02:31,100 --> 00:02:35,270
in its data field, a num num value.
29
00:02:35,820 --> 00:02:41,800
So found a corresponding corresponding node, ok.
30
00:02:41,940 --> 00:02:51,570
And of course in both cases if we found or if we didn't find, then we should simply move temp to the
31
00:02:51,570 --> 00:02:52,560
next node.
32
00:02:52,560 --> 00:02:55,200
So temp equals to temp next.
33
00:02:55,560 --> 00:02:56,490
And there you go.
34
00:02:56,730 --> 00:03:04,260
That's how you iterate over all the nodes of this linked list and you count how many times you found
35
00:03:04,260 --> 00:03:11,150
a corresponding node with a data field equals to NUM, which is this guy over here.
36
00:03:11,430 --> 00:03:17,680
And lastly, you simply return the count and that's how you do it.
37
00:03:17,700 --> 00:03:20,000
Guys, that's how you do it.
38
00:03:20,010 --> 00:03:23,730
That's how you tackle different linked list problems.
39
00:03:23,820 --> 00:03:25,780
That's how you work with pointers.
40
00:03:25,800 --> 00:03:31,890
I hope they at this point, you're starting to feel more confident about how pointers can be used.
41
00:03:32,340 --> 00:03:39,930
Of course, there are a lot of data structures that we may use for our practice, but for these section,
42
00:03:39,930 --> 00:03:41,370
I think it will be enough.
43
00:03:42,390 --> 00:03:45,420
And this is it for this video, guys.
44
00:03:45,420 --> 00:03:48,210
As always, let me know what you think about it.
45
00:03:48,660 --> 00:03:57,030
Feel free to to put some review, to write some comments and until next time, have a great day or evening,
46
00:03:57,180 --> 00:03:58,020
whatever it is.
47
00:03:58,270 --> 00:03:59,060
I'll see you then.
4581
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.