字幕表 動画を再生する
-
Hey, everyone
-
And this video,
-
I'm gonna give you a quick introduction to linked list
-
And in this video, I'm only gonna cover
-
the very basic of linked lists. But I'll cover more
-
advanced topics in a later video. Now a linked lists is
-
basically a data structure for storing a collection of item.
-
For example, these numbers
-
6, 3, 4, 2 and 1
-
and it does in a different way from the way an array does it
-
So as we saw in my previous video
-
an array can be visualized as a long box
-
with many partitions of the same size
-
and a linked list can be visualzed as
-
many boxes that are connected to each other
-
and the difference between an array and a linked list
-
will be more clear in a later video
-
But let's first focus on how a linked list
-
can be implemented in this video. Now each of
-
these boxes in a linked list can be represent as an object
-
And let's say the class for that objects is called
-
the Box
-
Actually we will rename it later. We're gonna change the name later.
-
but let's for now call it Box
-
And it's gonna have two attributes or 2 fields in this class.
-
and first one of those attributes is gonna be called 'data'
-
it's gonna be the data or the item
-
each box contains
-
so if you have... let's say the first box in a variable
-
called head
-
if you write head dot data
-
that's gonna give us this value 6 right there
-
that's the data - head the first box contains
-
and the type of data could actually be anything
-
it could be an integer. it could be a string
-
a character or anything else for there matter
-
but here I just assume that it's an integer. just for simplicity
-
And that's why I wrote int data here.
-
and the second attribute here or the second field
-
is gonna be called next.
-
That's gonna refers to the next box that's connected to
-
the particular box
-
if you write head dot next
-
that's gonna refer to the next box