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
- [Instructor] So, we're going to go ahead
and create a Linked List.
The type of Linked List we're going to create
is called a Singly Linked List.
Now, there are several versions of Linked List.
Another is W Linked List.
The one that we're doing, a Singly Liked List,
each node in that list stores the contents of the node
and a pointer or reference to the next node in the list.
It does not store any pointer or reference
to the previous node.
That's what a doubly Linked List does.
So, let's go ahead and get started.
If you're following along with the exercise files,
I am on chapter two, Linked List.
And within there, what you definitely want to make sure
that you do, whatever project that you are working on,
you right click on it, and set that
as the default startup project.
Now, I here, am working on the end state.
And when you open this up, you're going to see
my finished product.
But, to follow along, you can go into the begin state.
Which over there, has a blank plate
that you could start working on.
All right, so let's go ahead and jump right into this.
The first thing that we're going to want to do,
is create our node class.
So, I will drop down here on line 17,
and define a class called node.
And within here, we will add our first instance variable,
called data.
And there's a type integer.
Next is our node class itself.
And that's what makes it recursive
because we're define this node that's within node.
And the last thing we'll want to do here,
is to be able to display the content.
And so, I will define a straight forward display,
node, method.
And within here, the content of data.
And, just to make it a little bit easier on the eyes,
we'll put it within brackets.
And actually that's the greater and left hand symbols.
Now, technically brackets, for those of you
that are pointing out that flaw.
And there we go.
This will create our node class that can print out data.
Next, let's go ahead and create the Singly Linked List class
that will actually use this node.
I'll start off, just public class
and call it Singly Linked List.
And within here, we will have a private node
that I will call first.
Now the next thing that I want to do here,
is to add in a method that is called is empty.
That, as the name applies,
is to check to see if the node is empty.
Now what we want to check to see,
is if the first node points to null,
then we know that we have no nodes.
And that's what this value is going to return.
So, let's go ahead and enter in public,
and it's going to return a boolean type.
Check is empty.
And we will return the value of the first being null.
And that again is because if the first points to null,
we have no nodes that it needs to be known.
The next method we're going to write,
is to insert the first node.
It's going to be used to insert
at the beginning of the list.
So, we're going to call this insert first.
And, as a parameter, it will take in the integer type
of data.
And within here, our first step is to define a new node.
Create that instance.
And in the new node, we will assign it's data,
the value of data that was just passed in.
On the next line, we're going to assign it's property
of next to first.
And then lastly, we will have first equal two new node.
So, again what's happening is, we are assigning
this new node data passed in to this method.
And the new nodes next field should point to the first.
Now, let's set up a method to do the opposite.
Which is to remove a node.
We will call it delete first.
So it's removing a node, but specifically the first node.
And this is the great thing
about when you become comfortable with writing algorithm.
You can make it as powerful and as detailed as you want.
There's no limit to all the different functionalities
that you can add to it.
And this delete first method, I'll first define node
with the variable name as temp.
And I will assign it first.
And toward the bottom here, I'll go ahead
and just return temp to get rid of that.
Compiler.
I like doing that.
Just not having any squiggly lines
while I'm coding and disturbing my flow and concentration,
even though I only have one more line to write.
Which is the second line.
And that is to assign first to the next value of first.
The next method we are going to create is to display
the list and then also another one
for inserting a last node.
Those are up next.
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.