- 15 hours ago
Transcript
00:00Next we talk about how we can print our link list
00:03I have this link list
00:05in which I have element 1
00:081 point, 2 point, 3 point, 4 point
00:12and then finally null
00:14and my head value is here
00:16and my tail value is here
00:18so what I can say
00:20if I have only my head
00:22then I can traverse the link list
00:27how can I traverse
00:28in the form of next
00:30what I will do
00:31I will remove the next
00:33or I will take a temporary node
00:35I will say that the node is temporary
00:38and I will store the head
00:40as I have stored the head in temporary node
00:44so my temporary node is pointing to this node
00:49temporary is pointing to this node
00:50what I will do
00:52I will print the value of temporary
00:53I will print the value
00:54so I will print temporary data
00:58this means temporary
00:59which node is pointing to this node
01:01it will be structured
01:03which will have some data
01:05and next
01:06so I will print this data
01:08every time for temporary
01:15I will print the value of temporary node
01:17I will print the value of temporary node
01:29I will print the value of temporary node
01:37and now I can see this node
01:38I will print it
01:41and then I will print the nodes
01:43then I will print theева node
01:44and then
01:44i will print the node
01:49andו虐無
01:50No Once the nodes
01:52are
01:53apartheid
01:55If there is no null, I will go to the next node and I will print the data there.
02:00I store the head in a temporary node because I don't want to change the head.
02:08It means that your head is linked list.
02:12Head or tail will never change in the linked list.
02:16These variables are fixed by one way.
02:18When the linked list changes, they will change the variables.
02:21In this case, I will not change the linked list.
02:23I will print the link list.
02:25So I have created a new node, temporary,
02:27which I have kept the head value.
02:29Now I can change this temporary node.
02:31Head will not change.
02:33How will I change the temporary node?
02:34I will print the temporary data every time.
02:37After that, I will reach the next node.
02:40The next node means that the temporary will now be temporary.next.
02:45This means that the next node was temporary.next.
02:50Now my temporary value is temporary.next.
02:56When will I do these two steps?
02:58When will my temporary node be null?
03:00So I can add a while loop.
03:02When my temp is not equal to null.
03:06I will perform the two steps.
03:09First of all, print temporary data.
03:12Second step is temporary.
03:14Just to go into next.
03:15I will also visualize this.
03:18This is the link list,
03:20It will be four nodes.
03:22It will be four nodes.
03:23It will be near that here,
03:24my data will happen.
03:26Now here my data will be two,
03:28next.
03:29Then here my data will be three,
03:31next.
03:31Then my data will be four,
03:33next.
03:34and finally here the null value
03:36this is the point here
03:38and this is the point here
03:39and this is the point here
03:42I know my head
03:43and my tail
03:46at the beginning
03:47I am pointing here
03:49if I am pointing here
03:51then I will print here
03:52I have printed one
03:55after that my temporary
03:57is turned here
04:00then I am pointing here
04:03I will perform the same steps here
04:04first I will print the temporary data
04:07temporary data is 2
04:08and now I will change the temporary
04:10temporary to its next
04:11temporary will come here
04:12I will print the temporary data
04:14which is 3
04:15now I will change the temporary data
04:17which is 4
04:22now my temporary will come here
04:24finally to the null value
04:26like temporary is null
04:28I will break
04:29so I will write a loop
04:32in which I will print
04:33my linked list
04:35what do we do in the main function
04:37I have added 4 values
04:39last time in my linked list
04:40I have added 4 values
04:422 added first and 2 added last
04:45now I will create a method
04:47in my linked list class
04:49I will print it
04:51void print
04:53head has already
04:54so I don't need any parameter
04:57first I will create a new node
04:59temporary
05:00which I will add value
05:01in my head
05:02then I will run a loop
05:03while my head
05:05or while my temporary
05:07is not equal to null
05:11first I will print this temporary
05:18temporary
05:18temporary
05:18temporary
05:19temporary
05:19temporary
05:20temporary
05:20temporary
05:20temporary
05:20temporary
05:21temporary
05:21temporary
05:21temporary
05:21temporary
05:21temporary
05:21temporary
05:21temporary
05:22temporary
05:22temporary
05:22temp is equal to temp.next and in the last I will print my next line
05:27What is this? The base case here is that if my linked list is empty
05:34or if my head is null then in that case I want to print
05:40linked list is empty and here I want to do return
05:46I have written a special case for my null
05:48Besides these lines I can print my entire linked list
05:52What will I do in the main function?
05:55First I will call linked list.print
05:59After every step we analyze how to print
06:02my linked list changes in each step
06:05I will do linked list.print
06:09I will do linked list.print
06:12and here I will do linked list.print
06:15I will do save and run one more time.
06:19This series has been printed.
06:21In fact I will put an arrow here
06:24for the pointer
06:26and here it will be null
06:30What happened first?
06:32In the beginning the linked list is empty
06:33so the linked list will be printed.
06:35After that I have first added two
06:37So it became a single node
06:39and it is pointing to null
06:41I have printed it.
06:43Then I have first added one
06:44when I printed it
06:45and when I printed it
06:45then one had first
06:47and it has two
06:49then it is null
06:50Then I have added three
06:52so that three added in last
06:54in last
06:54First one
06:55then two
06:56then three
06:57then I am pointing to null
06:58Then I have added four
07:00so one
07:01two three
07:02before I came to last
07:04and then I have my null pointer
07:07If I want, I can remove my in
07:09which I had written in the special case
07:11In that case, the link list is empty
07:13I have only null printed
07:15If my link list is empty
07:17Then I have only null printed
07:19So after this operation, I can perform
07:22I can print my link list
07:24Or where I have to print
07:27If I have to perform any operation
07:29I have to loop my link list
07:31So in that case, what I have to do?
07:33I have to assign the value of head
07:35and then I will loop on temporary
07:37Because I cannot change my head
07:39and I cannot change my tail
07:41but I can change my temporary
07:43So in that case, when I have such a work
07:45or a question, we have to loop on the link list
07:48In that case, we will use this temporary variable
07:51And since the print function
07:53goes to every single node
07:55The time complexity of this
07:57will be linear time complexity
07:59which is big of n
08:00for one single node
08:01But I have to try to bring
08:01And to show the text
08:01такой