All language subtitles for 12. A Program to Rotate Left a given array by 1 positions - Solution

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

OK, so now let's try to solve it together, shall we?

First of all, let's also create maybe additional, I don't know.

Let's just use some define size for.

And let's create our array.

So let's use an array of integers, doesn't really matter.

OK?

Because we are simply doing it like they're so innocent.

Let's go with array of values of values, error of size, and it will be initialized through the following

values of five, four, seven and three.

OK.

That's it.

So you could read these values from the user.

You could do whatever you like, but for now, we already know how to read values from the user, how

to work with them.

So now what interests us is how we can simply make this algorithm of rotating to the left a given array

by one position.

So what is the main logic behind it?

What should be done?

What do you think?

What should be done?

OK.

So how can we take all of these elements and rotate them to the left?

If we would say, for example, like Valley, you say you are OK, values IRR at index, let's go size

minus one.

Equals.

To values a rather.

Values air at index zero, then that can be a problem, because after this operation, this value of

five would come here, right?

And the value of three will no longer exist.

OK, so that's a problem.

That's one problem.

The next problem is how you rotate all the other elements to the left.

Well, that's actually not the.

The most difficult thing in this exercise, because that's going to be probably a very simple loop that

will start from equal to one until I is less than size, right?

And then on every iteration you will simply use like values they are at index I equals two values.

Zero rate index minus one equals two values that are at Index II.

OK, so that's one of the options.

So that's about the for a loop of these parts.

But what about the others?

So what is important in this exercise is to understand that the precedence in this case who will be

done before the other is very important.

So what will we will do is the following we will see that we will create additional variable.

OK, we'll create like end temp, OK, temporary variable, and we will store inside of these temp variable.

We will store what we will store the value of error at index zero.

So we will say that values.

IRR at index zero, that would be the first step.

OK, so we have these temp with a value of five.

Then what we will do is we will rotate left.

I will show you in the code in a minute.

Rotate left.

All elements, all elements, OK, all elements from AI equal to one up to AI less than size.

So I'm just writing down the algorithm the main steps that we are going to do.

So after this operation, what we will get in the array?

OK, I just want to show you after this operation.

OK, rotate left all the elements from equal to one two, i.e. less than size.

We will have four, seven, three and three.

OK, this will be a duplicate that you will see.

And after this one will be over.

We will be able to say that values a RA at the last index, which is size minus one, will be equal

to what?

Did a value inside variable Tim, so we did not lose anything, neither from the left side nor from

their white one.

OK, so that's the whole explanation about it.

And that's the main steps that need to be taken care of.

Now with that being said, I hope it's clear so far what we will do is we will write the actual code

for it.

So let's create additional variable that will assist us in the process of looping.

So I, in what we will do, will create a variable and will also use the term variable for storing these

values so that the left most element or the right most element will not be overwritten.

So now what we will do is we will say temp equals two values, they are wrong at one index at index

zero.

Awesome.

Then what we will do is we will do a for loop and for a loop that starts from IE equal to one.

As long as I is less than size right, so far, so good.

I + +.

And we will say that values there come on at Index II minus one will be equal to value, 0r at Index

I.

OK.

Is it enough?

So what we do is we basically, first of all, took these value of five.

Put it aside, then we simply said, OK, so let's start and copy.

OK, I'm just going to map it to you right now.

So that's basically what we do.

We take these value offshore and put it inside here.

OK, so we say at index zero, put the value from index one.

So here we go four.

Then we take the same four, seven three and basically we are done right.

Because that's the last element.

Four ice equals to size minus one.

So that's the last element.

And we put it in the previous one.

So make sure that you start from equal to one because there is also an option to start with equal to

zero.

But then you will need to make sure that you do not go up until I's list in size, but rather ice less

than size minus one.

Otherwise, in this approach, you will probably make sure you did not.

But if you did this way, you are probably exceeding the size of the array.

OK.

The boundaries are awesome, so that's what we have at this moment.

And finally, all that remains once we are out of this for a loop is to say, OK, instead of this value,

we will use the value of faith in the value of five was stored inside the 10 variable and what index.

These value has this value, this element is with index size minus one.

So that's why we are going to do the following we will say values there are.

At index size minus one will be equal to temp.

OK, of course, all of that, not under the for a loop that's going to be right afterwards.

All right.

Is it clear, guys?

I really hope it is.

And basically after this operation, we have mustered and completed a story about that a program that

should rotate left a given a three by one position.

So you can try to print it out, okay, you can add the printing functionality, you can print this

array to make sure that it works, bring the array, whatever you like.

OK, it doesn't really matter because in this exercise, we basically try to focus and to make the best

in order to implement the logic, the algorithmic approach behind it.

Printing, you already know by now how to do so.

You can test it out.

Always just end the associated lines of code.

OK, so later on when you proceed and when you become better and better are developers.

You will see how you can take all of these functionality and put it inside a totally separate function

that will be called like, I don't know, rotates left by one position.

And this function will be capable of receiving an array and basically just making one rotation to the

left.

OK, but for now, that's the main important part.

We have created this program.

We are ready to move on.

So this exercise is the basis for a couple of additional exercises that I will show you in about a couple

of minutes, hopefully.

So thank you guys for watching.

Keep on practicing.

Keep on moving forward and you are bound to succeed.

I'll see you next time.

Bye.

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