- 15 hours ago
Transcript
00:00Hi everyone and in this chapter we are going to learn a new data structure called Linklist
00:04Now Linklist is a linear type of data structure
00:07Linear means we have learned the Arrays that we have visualized in this way
00:13We store data in the Arrays
00:16After that we have studied ArrayList
00:18What is ArrayList? ArrayList is a list of elements
00:22It is a list of data in which we store data
00:26And its size is dynamic
00:28Now these two data structures
00:31We have visualized data in a linear manner
00:35Our data was visualized in a single line
00:39In Arrays and ArrayList
00:41Linklist is a data structure in which we visualize data in a linear manner
00:46Like Linklist is shown in a chain of elements
00:51If I talk about integer 1
00:54It is an element in which I have connected with the next element or data through this chain
01:00After that I have connected with another data and connected with another chain
01:04And in this way I keep connected with data
01:08These chains are also known as this is a link
01:12This is a link
01:13Link is also known as the two things
01:14That is why I have a name of this data structure
01:17This is a link list
01:18And here the single data
01:20Or the single element
01:21Is a link list
01:23is that I have seen
01:25So when I have known a node
01:28I use a link list
01:28And a chain structure
01:29I call that it
01:30I call that a link list
01:31Now let us understand how a link list will be
01:34Now some details
01:34But if I have a link list
01:35If I have to visualize
01:36A link list
01:37A single data
01:38Or a single node
01:39Or an element
01:40I can visualize it
01:42As a single node
01:44There are two parts
01:44The first part
01:46Is the data inside
01:49or what information that node has stored.
01:52This data is an integer value, like it has stored 1.
01:55It can be a string, like if I store 1.
01:59It can be a boolean value, like true or false.
02:03It can be a floating value, like 3.45.
02:08So, this data can be anything.
02:09We need to know the type of link-list data
02:12so that we know which type of link-list is stored.
02:15Besides, another second type of information is stored.
02:20Which one?
02:21In a single node.
02:23Second type of information stored is next.
02:27What is next?
02:28Next is a reference.
02:31Reference, or in a simple language, a pointer.
02:35And where is the pointer?
02:37This pointer points, or the link is made to the next node.
02:42So, the next node is something like this.
02:44I can visualize it.
02:45And here, I will store 2 information here.
02:48What will store this node 2?
02:51What will store this node 2?
02:52Here, it will also be some individual data.
02:54And it will also be a pointer,
02:56which will point the next node.
02:58To point the next node to the next node.
03:00To point the next node to the next node.
03:02In fact, I can also visualize these links,
03:05which will point the next node to the next node.
03:08Here, there will also be a node.
03:10There will also be 2 information stored in this node.
03:12There will also be 2 information stored in this node.
03:13There will also be 1 store my data.
03:14And above that,
03:15there will be my next node's information.
03:17This will become my node 3.
03:20And where is the end of my link-list chain?
03:23There will also be a chain of elements.
03:25And there will also be a chain of elements.
03:26And there will also be a chain of elements.
03:26And there will also be a chain of elements.
03:27Where I store a null value.
03:30Null value is in Java.
03:33If we have studied math,
03:34we have null sets.
03:36Null sets means,
03:37So, if I want to show a null node,
03:40I will represent null in the form of null.
03:42Null means, in English, null.
03:44So, the structure of this way,
03:46this is my link-list structure.
03:48This is my node.
03:50In one node,
03:51I have created data.
03:52I can tell my type of data.
03:53From the beginning,
03:54I can tell my data.
03:55It is an integer type.
03:56It is a float type.
03:57It is a string type.
03:58It is a boolean type.
03:59It is a long type.
04:00With that,
04:01I store my reference variable.
04:04Because in Java,
04:06there are not pointers.
04:06In a link-list,
04:08we store pointers.
04:09But in Java,
04:10we store reference variables.
04:12Now,
04:13there will be a hint
04:14that this is next.
04:16Or in fact,
04:18reference variable
04:22Where did we study?
04:23We studied this in the OOPS class.
04:26So,
04:26reference variables are variables
04:28that point to an object.
04:29So, the reference variable is next.
04:31It is pointing to an object.
04:33And what is the object?
04:34It is a node.
04:35So,
04:36I can tell you that
04:37to make a link-list,
04:38I have to make a class.
04:41Which class?
04:43My nodes.
04:44Now,
04:44the different nodes
04:45are the object 1.
04:48This is my node class.
04:50This is my object 2.
04:51This is my node class.
04:52This is my object 3.
04:53This is my node class.
04:55This is my object 4.
04:56Which is basically null value.
04:58Now,
04:58the logic of the node class is this.
05:00This is the logic of the node class.
05:02This is the same type of information.
05:06So,
05:06I know that
05:07I know that
05:07a node is data.
05:09And that node is next.
05:10It will always be stored.
05:11So,
05:12I know that
05:13I know that
05:13I know that
05:14I know that
05:14I know that
05:15and when I know that
05:16I know that
05:17I know that
05:19I know that
05:22I have to use this concept.
05:23I know that
05:24we are applying
05:24to build our data structures.
05:27Now,
05:28I know that
05:29like Maruti Suzuki,
05:30if I know that
05:31I know that
05:32I know that
05:32I know that
05:33I know that
05:33I know that
05:34I know that
05:36I know that
05:38I will create
05:38and that
05:39I know that
05:41you know that
05:41I know that
05:41I know that
05:41I want to write
05:44my class.
05:45Then,
05:46I want to call my class.
05:49So I am going to keep my class's name node. What will happen in the node? What will I store
05:54in the node?
05:56The first information that should be stored in a node is its data.
06:00Let me store integer type data. So I will define int data here.
06:06And with that I will store next node's reference variable.
06:11So what can I say? This reference variable is next. What will it be?
06:15It will be the type node. Why?
06:19Because the next is pointing to this object
06:23which is already a node class object.
06:26So the next variable will be the type node type.
06:29So for the first time we are seeing that in a class
06:33which has a parameter defined, it is the class object.
06:37So this node is going to be the class object.
06:41And it is going to be a reference variable for another object.
06:43So I have defined this as next.
06:46Now what can I do in the beginning?
06:48I can create some constructors.
06:50The first one that I will create is public node.
06:55I will have some int data.
06:57And I will assign this data to my property.
07:01So I will write this dot data is equal to data.
07:05And what happens with this?
07:07What happens with this?
07:08What happens with this node?
07:10What happens with this node?
07:11What happens with this node?
07:13We will initialize this dot next with null value.
07:17Because at the beginning we assume that
07:19whatever we create node is not going to go ahead.
07:24So in this case we will do next to by default null.
07:27So to create a single node,
07:29I will create a class object first.
07:32What properties are in the class?
07:34There are two properties.
07:34One is my data.
07:35One is my next variable.
07:37And I have made a constructor for these two properties.
07:40I have also made a constructor.
07:40When we initialize this node.
07:42So we need to have data.
07:44What will data store in this node?
07:46Next will point it.
07:48If this next is pointing it.
07:51Then I will say that
07:52next is my reference variable
07:53will direct me to this object.
07:56In the beginning we assume that
07:57there is no other node.
07:59So my next is always pointing it.
08:01This is the linking process.
08:03When we understand the operations of Linklist.
08:06We learn to add to Linklist.
08:08We learn to delete it.
08:09We learn to print it from Linklist.
08:11We learn to create Linklist operations.
08:13We learn to create Linklist operations.
08:16We learn to perform different operations.
08:19But what do I need to do now?
08:21I need to create Linklist.
08:23And I am going to do that.
08:24With my help of node class.
08:25Basically if I will create many objects in node class.
08:28Then ultimately I will have a Linklist.
08:31If I will connect those nodes.
08:33I have created a class named Linklist.
08:36And the object of this class will be my linklist.
08:40Now what should be nodes inside the Linklist.
08:41What should be nodes inside the Linklist.
08:44In this class I will create another class.
08:47I will call it Public Static class.
08:51I will name it node.
08:52What should I define in node?
08:55One should be my integer type data.
08:58And with this I will have a node type.
09:00Next reference variable.
09:02To point my next node.
09:03To point the node.
09:04To point the node.
09:05Now I will create a constructor.
09:07I will create a public node.
09:08In which I have as a parameter.
09:11And now I will assign or initialize.
09:14I will release my node.
09:15This.data is equal to data.
09:17And this.next is equal to null.
09:20So in this way.
09:21I will create a single node.
09:24When I will create a single node.
09:26I will create a project.
09:26Let me create a single node.