1 00:00:00,770 --> 00:00:01,910 In previous lecture. 2 00:00:02,090 --> 00:00:08,480 We get what we expected here so are not chaining is working and we have a new data type named node. 3 00:00:09,110 --> 00:00:11,210 So as you can see here. 4 00:00:11,210 --> 00:00:16,340 So however a problem will occur since we can only store the integer data type to the value property 5 00:00:16,340 --> 00:00:19,040 of our node data type. 6 00:00:19,040 --> 00:00:25,430 So we should we create a new node, that type if we want to deal with another types such as float, 7 00:00:25,460 --> 00:00:27,110 boolean or character. 8 00:00:27,380 --> 00:00:30,500 Fortunately, the answer is no. 9 00:00:30,620 --> 00:00:38,600 If you recall our lecture in the playing with our templates in previous lectures, we can refactor this 10 00:00:38,600 --> 00:00:47,210 code node data type to handle not only the integer data type, but also all various data types available 11 00:00:47,210 --> 00:00:49,250 in C plus plus language. 12 00:00:49,250 --> 00:00:56,360 So here let's actually create our and edit our new node data class which here. 13 00:00:58,310 --> 00:01:01,670 And let's actually delete this here. 14 00:01:02,540 --> 00:01:02,870 Oops. 15 00:01:04,020 --> 00:01:04,500 Here. 16 00:01:04,500 --> 00:01:08,190 Delete this and let's go to. 17 00:01:09,040 --> 00:01:10,870 Are not class here. 18 00:01:11,510 --> 00:01:20,420 So here we have a public and let's actually create the node value and it's going to be the value we 19 00:01:20,420 --> 00:01:23,000 will pass the value to value here. 20 00:01:23,000 --> 00:01:30,110 And we will also, of course, this this is for our template, which we will create now. 21 00:01:31,180 --> 00:01:41,470 Uh, here outside the node class, we will template typename t and here the t value. 22 00:01:42,130 --> 00:01:42,790 Not like this. 23 00:01:43,120 --> 00:01:45,370 Here template. 24 00:01:48,800 --> 00:01:49,460 Aw yeah. 25 00:01:50,120 --> 00:01:52,910 He value here. 26 00:01:52,910 --> 00:02:00,170 Outside of this constructor here value we will pass value as value here and now. 27 00:02:00,260 --> 00:02:03,320 We will pass next here. 28 00:02:03,350 --> 00:02:05,720 Next null here. 29 00:02:06,470 --> 00:02:07,700 So now. 30 00:02:09,310 --> 00:02:10,690 As you can see here. 31 00:02:11,520 --> 00:02:15,500 Well, we optimized here so we can see this code snippet. 32 00:02:15,510 --> 00:02:17,550 We added constructor to the datatype. 33 00:02:17,580 --> 00:02:24,810 The initial actually let's create an initialization of the instance of the class that we will simplify 34 00:02:24,810 --> 00:02:27,150 the class here So we don't need this anymore. 35 00:02:27,150 --> 00:02:28,140 We don't need this anymore. 36 00:02:28,140 --> 00:02:29,850 We will assign it from zero. 37 00:02:29,850 --> 00:02:31,950 And here, as you can see, we got an error here. 38 00:02:31,950 --> 00:02:38,820 We will template the, uh, we have declared the template class here, which in this case I'm going 39 00:02:38,820 --> 00:02:40,590 to just make it a comment. 40 00:02:40,590 --> 00:02:43,080 So we will fix this later. 41 00:02:43,080 --> 00:02:49,440 But first, let's actually create our float nodes here, float node data types here, float here, the 42 00:02:49,440 --> 00:02:56,100 node, it's going to be Node one, the new node here, the here we will actually the implementation 43 00:02:56,100 --> 00:02:58,290 is quite easy as we did in previous lectures. 44 00:02:58,290 --> 00:03:01,320 The node here float. 45 00:03:02,840 --> 00:03:07,100 And in this case, for example, 3.14. 46 00:03:08,570 --> 00:03:10,160 And not here. 47 00:03:10,430 --> 00:03:11,600 Plot again. 48 00:03:12,230 --> 00:03:17,540 The node one or node to the new node. 49 00:03:17,750 --> 00:03:18,920 The float. 50 00:03:18,950 --> 00:03:22,310 And let's make it actually 5 or 6 point. 51 00:03:23,130 --> 00:03:24,120 In 92. 52 00:03:25,560 --> 00:03:26,000 Oops. 53 00:03:26,010 --> 00:03:26,580 Yes. 54 00:03:26,580 --> 00:03:27,630 Let's fix that. 55 00:03:27,990 --> 00:03:28,530 Here. 56 00:03:30,340 --> 00:03:32,160 And not float. 57 00:03:32,170 --> 00:03:33,820 Again, float. 58 00:03:33,970 --> 00:03:40,330 The note three Here we will create a three nodes here the node float. 59 00:03:42,390 --> 00:03:43,980 And in this case, it's going to be. 60 00:03:46,040 --> 00:03:48,260 9.25. 61 00:03:49,160 --> 00:03:56,060 So we can see that now we just need one line instruction to create a single node since it has a constructor. 62 00:03:56,060 --> 00:04:01,330 So the rest of the operation is the same as previous full node in previous lecture. 63 00:04:01,340 --> 00:04:01,820 The. 64 00:04:02,270 --> 00:04:06,380 But in this lecture the full node code for the node template, we will write it here. 65 00:04:06,380 --> 00:04:08,750 So as you can see, we added some code here. 66 00:04:08,750 --> 00:04:14,390 So this is the type name, the compare to previous lecture, the template type name here. 67 00:04:14,420 --> 00:04:16,130 Now we added this. 68 00:04:16,900 --> 00:04:22,140 And after that we will add the type name at the top of our print. 69 00:04:22,180 --> 00:04:26,800 Note here and we will print we will fix our print node here. 70 00:04:26,800 --> 00:04:28,540 And as you can see, we get an error here. 71 00:04:28,540 --> 00:04:33,250 That's because user class template node requires template arguments, argument deduction not allowed 72 00:04:33,250 --> 00:04:34,540 in the function prototype. 73 00:04:34,540 --> 00:04:38,500 So here we will add the template template. 74 00:04:38,530 --> 00:04:45,340 The type name type name will uppercase T and we got an error again because. 75 00:04:46,760 --> 00:04:50,480 The node here needs to get the template here. 76 00:04:50,480 --> 00:04:52,940 And as you can see, our error is fixed here. 77 00:04:52,940 --> 00:05:00,470 So as I said, it will print the initial node until it finds null for the next pointer that indicates 78 00:05:00,470 --> 00:05:01,940 the end of the node chain. 79 00:05:01,940 --> 00:05:04,790 So here this is the same as previous one. 80 00:05:04,790 --> 00:05:06,890 We will change it anything here. 81 00:05:06,890 --> 00:05:10,730 So we fixed our print node here. 82 00:05:10,760 --> 00:05:12,200 So now. 83 00:05:14,360 --> 00:05:20,270 Let's actually create our diagram here and see it on our eyes. 84 00:05:20,270 --> 00:05:21,540 So illustrate it. 85 00:05:21,560 --> 00:05:24,310 So here we have diagram. 86 00:05:24,530 --> 00:05:24,930 Oops. 87 00:05:26,640 --> 00:05:27,840 Here one. 88 00:05:29,260 --> 00:05:29,500 Aw. 89 00:05:29,500 --> 00:05:29,860 Yeah. 90 00:05:30,310 --> 00:05:32,250 So we will have one, two, Yeah. 91 00:05:32,260 --> 00:05:34,210 Four rows. 92 00:05:34,240 --> 00:05:35,140 One. 93 00:05:37,180 --> 00:05:37,900 To. 94 00:05:39,340 --> 00:05:41,890 Three and four. 95 00:05:41,930 --> 00:05:44,380 Here again, This. 96 00:05:48,580 --> 00:05:49,330 Here. 97 00:05:52,670 --> 00:05:54,080 Here and here. 98 00:05:54,410 --> 00:05:57,290 So in the left side, we have our. 99 00:05:57,840 --> 00:05:59,760 The values and pointers. 100 00:06:00,000 --> 00:06:05,580 So in this case, it's going to be let's actually make it the values. 101 00:06:13,180 --> 00:06:13,780 Values. 102 00:06:13,780 --> 00:06:16,210 And here we have pointers. 103 00:06:20,140 --> 00:06:21,460 Pointers. 104 00:06:21,940 --> 00:06:23,380 So here. 105 00:06:25,740 --> 00:06:30,030 Uh, our first node is 3.14. 106 00:06:30,060 --> 00:06:32,730 3.14. 107 00:06:32,730 --> 00:06:35,880 But the pointer is null. 108 00:06:37,890 --> 00:06:41,490 So here we have pointer null. 109 00:06:42,750 --> 00:06:44,610 And here we have. 110 00:06:46,120 --> 00:06:47,530 6.92. 111 00:06:47,680 --> 00:06:51,250 6.92. 112 00:06:51,250 --> 00:06:53,560 And the pointer is also null here. 113 00:06:57,690 --> 00:07:03,060 And here we have 9.25, the nine point. 114 00:07:04,510 --> 00:07:09,040 9.25 and it's also new. 115 00:07:15,850 --> 00:07:16,630 Here. 116 00:07:16,720 --> 00:07:19,210 So now after that. 117 00:07:21,850 --> 00:07:24,400 We will assign the pointers. 118 00:07:25,050 --> 00:07:26,400 So here. 119 00:07:28,420 --> 00:07:30,340 After the initializing our. 120 00:07:32,020 --> 00:07:32,590 Values. 121 00:07:32,620 --> 00:07:35,050 Now let's actually assign our pointers. 122 00:07:35,050 --> 00:07:45,700 So now we're going to node one pointer to node, one pointer to next is not two again, as we did in 123 00:07:45,700 --> 00:07:48,670 previous lecture add node to pointer. 124 00:07:49,950 --> 00:07:56,730 Next two are node tree here, and after that we will print the node. 125 00:07:57,680 --> 00:08:00,460 So in this case, it's it is not. 126 00:08:00,470 --> 00:08:02,150 We will print naught one here for now. 127 00:08:02,480 --> 00:08:03,860 So now. 128 00:08:05,690 --> 00:08:10,460 We are assigning the 3.14 and actually let's change this. 129 00:08:10,460 --> 00:08:20,060 So 3.14 chaining here to Node two here and we are assigning this here. 130 00:08:20,060 --> 00:08:23,950 So now actually we need to delete this null. 131 00:08:23,960 --> 00:08:31,340 Now for the for now this pointers doesn't so for example node one pointer doesn't show null here it 132 00:08:31,340 --> 00:08:37,040 shows the place in the memory of our Node two and node two shows the place on the memory of Node three 133 00:08:37,040 --> 00:08:37,370 here. 134 00:08:37,370 --> 00:08:40,490 So I will illustrate this right now here. 135 00:08:42,270 --> 00:08:49,050 So our node one pointer is chaining to our node two pointer here. 136 00:08:49,650 --> 00:08:53,610 Also our node two pointer here. 137 00:08:53,700 --> 00:09:00,330 Our node two pointer is chaining and showing our here to node three here. 138 00:09:00,360 --> 00:09:03,510 That's why we are printing node one for now. 139 00:09:04,080 --> 00:09:05,370 So now. 140 00:09:08,060 --> 00:09:10,700 Let's actually compile and run our application here. 141 00:09:11,330 --> 00:09:15,170 So close late previous quotes and outputs. 142 00:09:15,320 --> 00:09:22,290 The g plus plus, plus, plus main.cpp and exit here. 143 00:09:22,490 --> 00:09:28,340 And as you can see here, we are seeing firstly the three. 144 00:09:29,710 --> 00:09:31,810 Six and nine. 145 00:09:32,110 --> 00:09:36,160 So we are actually we need to write them in. 146 00:09:37,810 --> 00:09:38,560 Integer. 147 00:09:38,560 --> 00:09:40,690 So we just write them in integer. 148 00:09:40,690 --> 00:09:47,980 But actually, as you can see here, it's just refactoring our outputs and that's how your output is 149 00:09:47,980 --> 00:09:48,340 going to be. 150 00:09:48,340 --> 00:09:51,880 So I will also share this code with you here. 151 00:09:51,880 --> 00:09:53,620 So I'm waiting you in next lecture.