Hello and welcome to Java Point. And today, the topic of discussion is w circular link list
Prior to this, we have seen three link lists that is single link list
single circular link list, W link list. And now we'll discuss W circular links
And in w circular link list, we'll discuss the menu of W circular link list and create function
That is how to create W link. Let's start with W circular link list
First, we'll see the structure of a node. If I tell you about W link list
we have, we have already discussed W link list is a list where a node has three part
One data, one is address of previous node. One is address of next node
That is a node has three part that is data address of previous node and address of next node
So again, either it is W link this or W circular link. This node remains same
So we have a same structure. So we have created a structure having named node
There are three parts, one is data which is of integer type one is pointer
another is pointer. One next pointer will keep the address of next node
one previous pointer will keep the pointer of previous node. And the data type of both the pointers are struck node
Now you must be thinking why struck node, why not integer character? And so because if I tell you
if I tell you about w link, if I talk about this address
this address is not a simple address. This address is address of a node
And this no itself is a structure which is having three parts
That's why this data type is also off type structure fine because of this
this kind of structure are known as self referential structure because of this
these kind of structure are known as self referential structure. And what we did finally
we have created a variable of structure by name node one, you can write a B whatever it is
but I have used node one because it looked more no more related
Finally, I have type defined this structure by type defining means I have created uh I have actually
you know, asked this variable to represent the entire structure means now node one will represent the entire structure if you are still confused
Let me give you one very good example. Suppose we have we are making a program c program white man
And inside main, we have created a variable in James. James is a variable of type in
Now what we did, we have type defined it, type, defined it by type defining it means we have created James of type
in. Now if I use James A KB, then this means that A and B are of type James and James is of type integer
means A and B are of type integer. This means now James is acting as a representative simply in a similar way
Node, one is acting as a representative of what this entire structure
Hope you have understood what this structure is all about. And let me show you the structure of a node
So this is the structure of a node. The name of node is 10. The address of node is 200
If I talk about 55 is a data of a node. If I talk about 101 100 is address of previous node
If I talk about 303 100 is address of next node. So this is all about the structure of W link
list, a structure of a node of W link list. So there is no difference between W link list and W circular link
This only there is a difference between connection. So if I talk about node structure
there is no difference between uh there is no difference in node structure of W or W circular
So the structure remains same. So I've tried my level best to explain you first structure unless and until you will understand the structure of
a node, you won't be able to understand anything fine. So let's start and start and understand the menu of W link list
So we have a menu of W link list in menu. What we did in main function
we have created a variable ch of integer type. And then we have used V one V one means what condition
Always condition, always true. What is, what is the meaning of condition
Always true? Because in condition part, you are giving one, if you give one
you give 100 you give five, you give minus two, whatever you are giving other than zero is always true
So something which is other than zero is always true. So condition will remain always true
Now in Y loop, you have five print statement where first statement is saying one is for create two is for print three is for
insert, four is for delete, five is for exit, exit. And six statement is saying enter your choice in a similar fashion
Whenever you go to a restaurant, you have a menu and menu, there are different dishes and then you order bring dish number 23
whatever it is. Now as your job is to create the link list
what you will do. First of all, you will press one, the moment you will press one C will have one switch will have one
it will jump to case one. And in case one, we are calling a function
we are calling a function we are calling which function create function
So what will happen. I'll jump to a create function. The moment I'll jump to a create function I have seen again that I have
created a pointer named term of data type. Node one, what is node one
I have just explained to you that what we have created a structure having three part one data and two addresses
And the representative of this structure is node one because we have type defined it finally
Now if I ask you in this area in this portion, what is the link list
Can you see the link list? You will say no, I cannot see link list
No, I cannot s link list because there is no link list. So because of that
since we have not yet created any link list. So head and tail which are two point head is the pointer which is pointing to
the first node, tail is the pointer which is pointing to the last node will have null value
Because if there is no link list, then head and tail both will have null value and head and tail
Both are pointer. And their data type is what node one? Because here we only discuss of data type
Node one finally. Now what will happen now see what happens since we have to create a note
So what will first line you have? No, I have tried my level best to explain you
First line. Now second line, what is second line I have to create link list
This means I have to create a node. And in order to create a node, we have a dynamic memory allocation function
Malo. So Mao is a dynamic memory allocation function which create a memory
Now, what kind of memory you are looking for? I'm looking? Or node one memory size of is an operator
I'm asking me to create a memory of size. Node one, what is node one
node, one is a representative of a structure which has three part one data and one address
The moment I do this part, a node will get created. A node will get created having three part one data and two addresses because
this node is of having size nodes. Now finally what Malo written Mao written address of address of memory it created
So suppose the address of this memory is 100. So this address is written to temp why temp
Because temp is a pointer and pointer hold the address. So so this temp this temp is having had address 100
Finally, now you must be confused about what is node one since we are returning the address
this address is not a simple address. This not is an integer address, correct address of all no address
This address is address of a structure which is of node one type because of that we have type C it with node one
So in second line, I have tried to explain you how node is get how node is creating third line
Since I've created a node, I will ask user to enter the data. I'm asking user enter the data
the moment user will enter the data. So where I'll put the data, I'll put in the address of T data part that data suppose
user has entered four. So I'll put in a data part four. Finally what will happen
I'll move to this line and I'll check is head equal to null is head null
Yes, condition is true because currently we have head also null, we have tail also null because since if there is no linkage
then head and tail both are null. So condition become true. The moment condition become true
I'll move inside what I'll do, I'll initialize head with temp. What is tamp 100
So head will have 100. So head will come here tail with temp
So what is tamp 100? Tail will also have 100 fine. So head and tail both have 100
OK. So I have tried to explain you these two lines that head will become temp and tail will become tamp fine
Why? So because head and tail, head and tail will have value of and temp is 100
So head and tail will come to the node having address hunt. Now what will happen
Now, the important part is that in doubly circular link list, tail keeps the address of head and head keeps the address of tail
That is next part of tail keeps the address of head and previous part of head keeps the address of tail
So what am I doing this tail next? What is tail next? This is tail next and this is head next also because now all
the three pointers are at same position. So tail next, this will have head
What is head, head is 100. So the moment I put 100 over here
it will start pointing to this note fine. OK. And what next head previous
what is head previous and head previous? What is head previous? This I'm talking about this
This is also tail previous. But now as we are representing head
So uh head previous in head previous, we are putting tail, what is tail
Tail is also 100. So the moment I put 100 over here, so this node will start pointing which node this note finally what happened
One node is there, which is pointing to itself. So is now my job is over
Now, since if it's executed, will I execute else? No, I'll come out
I'm I'll come out of this create function and wherever where I'll go, I'll go backside from where I have received the call
So from where I have received the call, I have received the call from a one
I have received a call from this menu. So I've received the call from this place. So when I have received the call from this
place and the next line of this is break. Break means what I'll come out
I'll come out of switch, switch. The moment I come out of the switch
I'll find end of loop. Will I come out of the loop? No loop will never allow me to come out because loop will ask
me to go and check the condition, the moment I'll go and check the condition. Since the condition is always true
Since the condition is always true, what will happen? What will happen again
I'll see those menu. Why? Because if suppose a waiter is standing in front of you and he will ask you
sir, what do you want? Next one? For create two for print three, for insert four for delete five for exit
What is your choice? So what I'll do now, I'll again create because I want to create what I'll do
I'll again press one the moment I press one ch will have one switch will have one in case one again
I'm calling again, I'm calling what create function. So what will happen again
This create function will be called. Now, one thing very important is that if I say now let me create this uh node
here. Let me create this node here. This node was t suppose there was 400
So there was also 100 there was also 100. This node was pointing to this
this node was pointing to this. The node name was head. This name was tail
Now, very important part which I would like to tell you is that the moment you come out
the moment you came out from create function, this stamp variable, this stamp variable which is local variable will get destroyed will get destroyed
Why? Because temp is a local variable and the life of local variable is only in the block in which it is created fine
The moment you come out of the block, create block, it will get destroyed. Why not head and tail
Because head and tail are are global variable. They are global and their life will remain till the program is executed fine
So head and tail will remain. So finally, what happened? You have again uh you know
create function is again called again this melo again, this melo will create a note
So again, this melo will create a node having named TM and suppose the address of this node now is 200
Now what will happen? I'll ask user to enter the data again, I'll ask user to enter the data because again
I've created a note suppose user has entered six to where six will go
Tamp data part six will go in temp data part six will go
So in tamp data part, so six will go in temp data part six will go
Now what happened? What will I see is head equal to null
No, now head is not null because head is pointing at not having address 100 tail is also not null because tail is pointing at
not having address 100 fine. So this condition become false. So I'll not move in this block
I'll move to the block now tail. Next. What is tail? This tail
what is next? This tail next will have temp. What is T 200? So here we have 200
Now the moment I'll have 200 now this node will start pointing this node tail next is pointing tamp 200 fine
So this pointer will get destroyed. Now what will happen? Tamp previous
What is tamp previous? This one will have tail. What is tail 100 so 100 will come here
So this will start pointing this fine. OK. Tail is going to temp what is temp 200
So tail will have 200. So tail will jump from here to here. Why
Hair to hair? Because because because you know tail is the last note fine
So tail came to the last part. Finally, tail came to the last part
OK. Now what I told you to remember, I told you that tail next will have had tail
This node is tail. Now next is this we have head. What is head 100
So the moment you put 100 this node is pointing to what this node fine
OK. And head previous what is head previous? This part will have tail
What is tail 200. So here what will come 200? So do more moment
I'll put 200 this link will get broken and this head will now keep the address of this node
So this is how you know linking is taking place. The moment you keep on adding the node
the moment you keep on adding one in menu, the node will get created again and again
So let me rub all this no uh code and show you the exact diagram
So if you see the exact diagram, so this is exact diagram which is showing that you have pressed four times one when you have
pressed four times one. Because of that four nodes that had been created
And the last node which is tail is keeping the address 100 that is address of head head address is 100 and they had previously
keeping 400 which is address soft tail. So this is why because of this
this is called doubly circular link list. So I have tried my level best to explain you what is do circular link list all about
So at last, I'll say thank you so much for watching Java Point. Please like subscribe and share the channel
Thank you. Thank you so much. Thank you very much