Afrikaans
Akan
Albanian
Amharic
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
Hungarian
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
In this video we're going to talk about a data structure and how we can use it.
And so what it's called is a stack.
And we're going to talk about two different ways it can be implemented.
One with an array and the other with the link list.
And so here in our first array implementation we have an array here and we have nine elements we're
not to use anywhere near that much for this visual demonstration.
And to use a stack It's pretty basic so if we want to put the first in the stack it 43 hit push and
we just put 43 right in that zero element.
Now the stacks are pretty straightforward.
So if I want to put the value five I push that on and push is the method that adds on top of it.
And so that 5 simply gets added directly to their array.
If I want to put AIDS I push that and we can just keep on going down the line.
And we're just going to put a couple more just so you can see exactly how that works.
Thirty three goes next and the last one we'll do is two.
OK.
So now we have a pretty basic array and it's a stack meaning that in order to access these items we
simply can access this very last item right here.
So if we want to we have to do something called a pop.
And so if I click pop it's can take that value.
It's Gager the 5 element.
And now that pop value is equal to 2 and we can use that too in our program.
Good way to actually visualize it in addition to these type of systems is to take a real life example.
And my favorite is a stack of books and because we're talking about stacks I thought a stack of books
would be a great analogy.
So our first element in the stack is this brown book here on the bottom.
Every time we push we're pushing a new book on the stack.
So we would push the screen book onto it.
This black book Blue one red one and the orange one.
And so we now have a stack of books six total elements right here just like we have right on this side
or we had until we popped off that last two.
So this one would represent the two.
Now if we were to take or pop this last element off of the stack we would simply take it off and then
we could read it and then we would be left with the remaining five books right here and any other ones
that we wanted to read we couldn't you know go grab in the middle.
We actually had to take them off and pop them off one at a time.
So that's how a stack is really visualized that's what helped me learn.
My first time now that this is with an array.
Now the other type of implementation that's popular is with a linked list and the only difference with
this is that the linked list has a pointer to whatever value is below it.
So if we put in if we push on 11 this 11 gets put on the top of the stack and then if we put 55 55 gets
pushed to the top of the stack and you can see it has a pointer to 11.
So everything knows what is below it.
So if I want to put 61 I put 61 inside 61 goes to the top of the stack.
It has a pointer to 55.
And if you don't know what pointers are.
Don't worry it just it literally means it's pointing to whatever that value is below it.
So a good way of thinking of switching back to our book example is that the Orange Book knows that the
read book is below it.
The Redbook knows the blue one is below it except for all the way down the line that part of it is pretty
straight forward here.
And we have the same exact implementation we have push and pop and then if we want the 61 value or whatever
is on the top of the stack we click pop and the pop value goes into whatever we called it whether it's
a function or in a variable and it gets removed from the stack and we're left with those remaining two
elements.
And that's essentially all there is to a stack.
So please let me know if you have any questions whatsoever and I'll see in the next video.
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.