Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:00.08 --> 00:00:04.06
- [Instructor] A common
algorithm is called a Link List.
2
00:00:04.06 --> 00:00:07.06
And sometimes you might hear
technical definitions such as;
3
00:00:07.06 --> 00:00:11.09
it's a linear collection of
data elements called nodes.
4
00:00:11.09 --> 00:00:15.07
Each pointing to the next
node by means of a pointer.
5
00:00:15.07 --> 00:00:17.09
But really, if we're talking straightly,
6
00:00:17.09 --> 00:00:20.05
it's a collection of items like arrays,
7
00:00:20.05 --> 00:00:23.04
but with less limitations.
8
00:00:23.04 --> 00:00:26.05
For example, there are
some cons to using arrays.
9
00:00:26.05 --> 00:00:29.01
Slots in arrays can't be increased.
10
00:00:29.01 --> 00:00:33.07
If you have 50 slots,
you can't just add 51.
11
00:00:33.07 --> 00:00:36.06
What you have to do, is
to recreate a larger one
12
00:00:36.06 --> 00:00:40.02
and then copy over the data,
and that's inefficient.
13
00:00:40.02 --> 00:00:42.03
Also, you can't insert items into an array
14
00:00:42.03 --> 00:00:44.04
without having to do extra work
15
00:00:44.04 --> 00:00:46.09
to reassign all the items over.
16
00:00:46.09 --> 00:00:49.05
Arrays have fixed size
with these limitations.
17
00:00:49.05 --> 00:00:52.02
But for Linked List, you don't have this.
18
00:00:52.02 --> 00:00:55.03
You can insert data in the
beginning, in the middle,
19
00:00:55.03 --> 00:00:57.03
or the end of the list.
20
00:00:57.03 --> 00:01:00.09
These box combinations
are referred to as nodes.
21
00:01:00.09 --> 00:01:03.03
The three with the blank
box right next to it,
22
00:01:03.03 --> 00:01:04.02
that's one node.
23
00:01:04.02 --> 00:01:06.04
The five with the blank box
next to it, that's one node,
24
00:01:06.04 --> 00:01:07.09
and so forth.
25
00:01:07.09 --> 00:01:10.07
The beginning of the list
is referred to as the head.
26
00:01:10.07 --> 00:01:13.09
And the end is referred to as the tail.
27
00:01:13.09 --> 00:01:16.05
If we were to have an analogy of a train,
28
00:01:16.05 --> 00:01:20.08
you could think of each
car below as a node.
29
00:01:20.08 --> 00:01:23.00
They contain the data that you want.
30
00:01:23.00 --> 00:01:25.09
And that's what we call them
in a Linked List, nodes.
31
00:01:25.09 --> 00:01:29.02
You can add and remove as
many nodes as you want.
32
00:01:29.02 --> 00:01:31.04
In our Linked List, each
node points to another node,
33
00:01:31.04 --> 00:01:34.06
or it's null, such as the last node.
34
00:01:34.06 --> 00:01:36.03
Here, if we wanted to drop the five,
35
00:01:36.03 --> 00:01:39.02
we can point three to four.
36
00:01:39.02 --> 00:01:41.06
If we're looking at the
node here with three,
37
00:01:41.06 --> 00:01:44.04
when coding, the way we
create class definitions
38
00:01:44.04 --> 00:01:49.03
is by thinking of each node as
an instance of a node class.
39
00:01:49.03 --> 00:01:50.09
Just like here.
40
00:01:50.09 --> 00:01:52.07
The class definition of node
41
00:01:52.07 --> 00:01:55.03
would contain two instance variables.
42
00:01:55.03 --> 00:01:58.01
One of type integer for the number.
43
00:01:58.01 --> 00:01:59.05
That's where the data is.
44
00:01:59.05 --> 00:02:03.04
And the other, where you see
the word next, is of type node.
45
00:02:03.04 --> 00:02:05.09
And that points to the next node.
46
00:02:05.09 --> 00:02:07.07
Just like how we see next is pointing
47
00:02:07.07 --> 00:02:09.09
to data in these nodes.
48
00:02:09.09 --> 00:02:11.07
Let's go ahead now and
just jump into some code
49
00:02:11.07 --> 00:02:13.05
to demonstrate this.
3807
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.