All language subtitles for 2. Count of Nodes in a List

af Afrikaans
ak Akan
sq Albanian
am Amharic
ar Arabic
hy Armenian
az Azerbaijani
eu Basque
be Belarusian
bem Bemba
bn Bengali
bh Bihari
bs Bosnian
br Breton
bg Bulgarian
km Cambodian
ca Catalan
ceb Cebuano
chr Cherokee
ny Chichewa
zh-CN Chinese (Simplified)
zh-TW Chinese (Traditional)
co Corsican
hr Croatian
cs Czech
da Danish
nl Dutch
en English
eo Esperanto
et Estonian
ee Ewe
fo Faroese
tl Filipino
fi Finnish
fr French
fy Frisian
gaa Ga
gl Galician
ka Georgian
de German
el Greek
gn Guarani
gu Gujarati
ht Haitian Creole
ha Hausa
haw Hawaiian
iw Hebrew
hi Hindi
hmn Hmong
is Icelandic
ig Igbo
id Indonesian
ia Interlingua
ga Irish
it Italian
ja Japanese
jw Javanese
kn Kannada
kk Kazakh
rw Kinyarwanda
rn Kirundi
kg Kongo
ko Korean
kri Krio (Sierra Leone)
ku Kurdish
ckb Kurdish (Soranรฎ)
ky Kyrgyz
lo Laothian
la Latin
lv Latvian
ln Lingala
lt Lithuanian
loz Lozi
lg Luganda
ach Luo
lb Luxembourgish
mk Macedonian
mg Malagasy
ms Malay
ml Malayalam
mt Maltese
mi Maori
mr Marathi
mfe Mauritian Creole
mo Moldavian
mn Mongolian
my Myanmar (Burmese)
sr-ME Montenegrin
ne Nepali
pcm Nigerian Pidgin
nso Northern Sotho
no Norwegian
nn Norwegian (Nynorsk)
oc Occitan
or Oriya
om Oromo
ps Pashto
fa Persian
pl Polish
pt-BR Portuguese (Brazil)
pt Portuguese (Portugal)
pa Punjabi
qu Quechua
ro Romanian
rm Romansh
nyn Runyakitara
ru Russian
sm Samoan
gd Scots Gaelic
sr Serbian
sh Serbo-Croatian
st Sesotho
tn Setswana
crs Seychellois Creole
sn Shona
sd Sindhi
si Sinhalese
sk Slovak
sl Slovenian
so Somali
es Spanish
es-419 Spanish (Latin American)
su Sundanese
sw Swahili
sv Swedish
tg Tajik
ta Tamil
tt Tatar
te Telugu
th Thai
ti Tigrinya
to Tonga
lua Tshiluba
tum Tumbuka
tr Turkish
tk Turkmen
tw Twi
ug Uighur
uk Ukrainian
ur Urdu
uz Uzbek
vi Vietnamese
cy Welsh
wo Wolof
xh Xhosa
yi Yiddish
yo Yoruba
zu Zulu

Original subtitles

What is going on, guys, so in this video, what we are going to do is to write a function that counts

the number of nodes in a given linked list.

These functions should basically just receive, receive, receive a list, OK?

It should receive at least then you should count how many nodes are there in that list.

And finally, it should return these count.

Pretty simple, right?

Nothing complicated.

Just receive a list.

OK, get a list.

Count how many nodes there are in this particular list and return these count to whoever called these

function in.

The first thing to note here is that as opposed the two static arrays, for example, we cannot know

in advance what is the size of a linked list.

We simply usually have a pointer to the head of the list and that's it.

We don't have the exact number of nodes that it currently has because we said that we will mostly use

lists as our preferred data structure for tasks or where there are frequent changes in when we have

frequent changes, we cannot know the size of the of the linked list.

And also one question that I've been asked a lot is actually goes like this.

Why do we have to write a function?

Can't we just use size?

So that's one of the questions I've been asked.

So why do we have to write a dedicated function for that, something like that and dedicated function

for that?

Can't we just can't we just use size of OK, the size of operator and will tell us the exact size of

the linked list.

So actually we know that was linked list.

We work with pointers.

We have our head pointer pointing to the head of the list.

For example, we know we have a list with a couple of nodes and we want to find out how many nodes are

there in that list.

We simply can just use the size of because what should we put in the parentheses of this, of the size

of should we put just the hand if we do so, something like that.

So size of size of had we had a pointer, we will simply get the size of a single pointer had and obviously

not the size of the whole list, not even the size of the node itself.

It will be just the size of the pointer.

So I think that's a good idea.

Why size of won't work here.

The size of operator.

But if you still think something can be done with that, please try it out and let me know.

That's an important part of the starting process.

OK, so let's move on and write our a simple function.

OK, so there you go.

So first of all, what we created here is the template structure for the node in our linked list in

what we will do is just to write a function.

OK, so we know that the function returns.

What it returns, it returns.

The count right account account is simply an integer.

So the signature is going to be of an integer type and then we will specify the function names or for

example, count nodes in list.

OK, and what should the function receive?

The function should receive some some address that in this address we have the first node in this list.

So what we can do here is simply to use node star, OK, because we receive the address of the first

element and we have here node star had OK, for example, we're receiving the address of the first node

in the list and now what we want to do is to write the function body.

So for that we will create int count, OK, we will set it to be zero and this will be the count of

the nodes in this in the list.

So Count will represent the count of the nodes and also just for simplicity.

But it's not mandatory.

Let's create some additional pointer, call it let's call it temp, OK.

And we will set temp to point to head.

OK, so we'll steal.

Although it doesn't really matter in this function, we will still keep the head of the list pointing

to the head of the list and temp will simply iterate, kind of iterate and run over each in any of the

elements in this linked list.

So now what do we.

Have to do is to write a simple loop that will iterate over all the elements, and as long as we haven't

reached the last element, we will use count plus plus.

OK, so while in here will be some condition, as long as this condition is true, then count plus plus

and we will use temp equal to town equals to temp next.

OK, so every time we will take the 10 pointer and point to the next element in this linked list.

OK, so the main question that should be asked here is basically what should be the condition in these

while loop?

So if we want to say what will be the condition in just our words, we will say that the condition would

be as long as we haven't reached the end of the list.

OK, so as long as this is OK, we will run the body of this loop.

So while and how we will treat this part like haven't reached the end of the list.

So we know that every every, every node has a data and it has a next pointer.

And one thing that we know about lists is that the last element in the list should point.

These next field should point to null.

That's what specifies that the list ends in this given node, because in the standard ways, that's

how we find the length of the list.

OK, and that's how we find the end of the list.

So simply, as long as we can say that temp next, as long as the next temp does not equal to null.

OK, so if a given node that temp points to if it has a next field and this next field points to no

meaning, we don't have any further nodes, meaning we are at the end of the list.

And that's why we should like finish up with this condition.

The result of the condition should be false and we should be out of the loop in once we are out of this

loop.

We have been iterated.

We have iterated over all the elements of this linked list, count all of them, and we simply will

return the number that we have found.

So return count.

So int count counties of Taipei and the type the signature, everything seems to be OK.

So there you go, guys.

This is our function to count the number of nodes in a list.

So count number of nodes in a list.

Awesome.

Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.