1 00:00:01,330 --> 00:00:02,050 Hi, everyone. 2 00:00:02,080 --> 00:00:06,660 So in this video, we are going to solve this question for all the politicians of an element. 3 00:00:06,970 --> 00:00:12,250 So, for example, if this is your ready, five, six, five, six and six. 4 00:00:14,770 --> 00:00:17,050 Index zero, one, two, three and four. 5 00:00:17,300 --> 00:00:22,750 Let's say the value of excess five, so five is present at index zero at the next two. 6 00:00:23,410 --> 00:00:26,530 So five is present at zero at the next two. 7 00:00:26,770 --> 00:00:28,620 So we have a really solid discussion. 8 00:00:28,630 --> 00:00:30,400 But in that question, we were printing. 9 00:00:30,640 --> 00:00:31,960 So we were not storing. 10 00:00:31,960 --> 00:00:33,130 We were printing only. 11 00:00:34,060 --> 00:00:39,270 But in this question, what we need to do so we need to store the position, some of the value of excess 12 00:00:39,310 --> 00:00:44,090 sex, so sex is the next one at the next three at the next four. 13 00:00:44,440 --> 00:00:47,860 So we need to store these indexes one, three and four. 14 00:00:48,010 --> 00:00:51,110 So we need to store this index and we do not need to print. 15 00:00:51,370 --> 00:00:52,860 So the question is a little bit different. 16 00:00:52,870 --> 00:00:53,620 We need to store. 17 00:00:54,620 --> 00:00:58,310 So whenever you want to store multiple things so we can use every. 18 00:00:59,780 --> 00:01:01,010 Or we can use vector. 19 00:01:02,780 --> 00:01:06,360 So we can use that to store or we can use vector to store. 20 00:01:07,100 --> 00:01:11,000 So what we do, we will modify our solution for all position. 21 00:01:11,000 --> 00:01:15,620 If you remember, we have already sold this question print operation, so we'll just modify it. 22 00:01:15,800 --> 00:01:22,520 So instead of printing what we will do, we will pass a vector ordinary and we will store the indexes 23 00:01:22,520 --> 00:01:24,230 inside that vector sample. 24 00:01:27,480 --> 00:01:28,440 So what we need to do. 25 00:01:30,530 --> 00:01:35,690 This is our Brendle position function, we just need to update this function, so let's copy this function 26 00:01:35,690 --> 00:01:36,440 and we will update. 27 00:01:42,640 --> 00:01:44,050 So let's remove it from here. 28 00:01:47,130 --> 00:01:50,490 So what to do to change the name of the function so we will not print. 29 00:01:50,640 --> 00:01:51,600 We will save. 30 00:01:52,710 --> 00:01:53,760 Seybold position. 31 00:01:55,510 --> 00:01:58,370 So for saving the position, what do we need to do? 32 00:01:58,390 --> 00:02:01,370 We need to take that as input or we'll take that input. 33 00:02:02,050 --> 00:02:07,470 So let's say I am taking a vector as input vector in, let's say answer. 34 00:02:08,669 --> 00:02:11,520 So this Victor of all the politicians. 35 00:02:12,560 --> 00:02:13,400 So, Victor. 36 00:02:17,970 --> 00:02:24,060 The Jesus answer, this letter is initially empty, let's call this function, see what position. 37 00:02:28,230 --> 00:02:34,190 I will pass, Eddie, I will pass and I will pass, I will pass starting next, which is zero. 38 00:02:34,650 --> 00:02:41,490 So the value of this I want to search for, I want to store all the positions for five zero is the starting 39 00:02:41,490 --> 00:02:41,870 next. 40 00:02:41,880 --> 00:02:44,100 And I need to pass the vector, which is answer. 41 00:02:47,250 --> 00:02:48,840 So what will happen, dysfunction? 42 00:02:49,730 --> 00:02:56,120 Will update this letter and then I need to print that letter to check whether the output is right or 43 00:02:56,120 --> 00:03:04,250 wrong, so let's the vector so I equals zero I less than what size I placeless. 44 00:03:06,970 --> 00:03:07,600 Setout. 45 00:03:09,090 --> 00:03:09,960 And set off a. 46 00:03:11,380 --> 00:03:15,700 So let's rename the vector to the Vector V. I am passing the pervy. 47 00:03:16,580 --> 00:03:18,530 And this is the profi. 48 00:03:22,530 --> 00:03:28,940 Simple, so there is one problem with this code and it is the problem, so we need to pass the Turbit 49 00:03:29,010 --> 00:03:34,290 offense because we want whatever changes the evaluation function do. 50 00:03:34,920 --> 00:03:37,940 So all the changes should be reflected in this report also. 51 00:03:38,370 --> 00:03:42,440 OK, so we need to pass it by reference and let's update this function. 52 00:03:42,450 --> 00:03:45,150 So if I Coalson, I am returning. 53 00:03:45,810 --> 00:03:49,760 So instead of printing, instead of printing the index, I restore the index. 54 00:03:50,070 --> 00:03:52,490 So answer not wish back. 55 00:03:53,280 --> 00:03:57,150 We will not print the index, we will store the index pushed back I. 56 00:03:58,080 --> 00:04:01,980 And here we need to pass director answer Victor. 57 00:04:02,750 --> 00:04:06,960 OK, so I think our court will work and we need to change. 58 00:04:07,290 --> 00:04:11,120 So this is not this is save save oil pollution. 59 00:04:12,050 --> 00:04:14,360 OK, so I think our function will work. 60 00:04:15,000 --> 00:04:17,519 So I am printing all the positions of five. 61 00:04:17,880 --> 00:04:21,510 So five is present at present zero, one and three. 62 00:04:26,640 --> 00:04:32,160 So I am using Vector, but I have not included the header file, so let's include the added file. 63 00:04:38,480 --> 00:04:40,520 So the output should be one, three and five. 64 00:04:40,550 --> 00:04:42,160 And what's the error here? 65 00:04:43,310 --> 00:04:49,550 OK, so basically it doesn't know what is and is basically the number of elements, which is six one, 66 00:04:49,550 --> 00:04:51,080 two, three, four, five and six. 67 00:04:55,210 --> 00:04:59,520 So element five is present, it makes it Heidi Nexon added in next. 68 00:04:59,750 --> 00:05:01,000 So our function is working. 69 00:05:03,150 --> 00:05:03,960 So let's see. 70 00:05:04,830 --> 00:05:08,550 So let's give the value six six present to the next two and four. 71 00:05:10,040 --> 00:05:11,370 Success by then next to. 72 00:05:11,750 --> 00:05:12,950 Let's give the next seven. 73 00:05:15,270 --> 00:05:23,910 Seven is that next five, so I put this five and let's give a value which is not present, so output 74 00:05:23,910 --> 00:05:27,220 should be empty, our factories and producers will not print anything. 75 00:05:28,050 --> 00:05:30,180 So basically, our function is working. 76 00:05:31,790 --> 00:05:37,820 So a better way of solving this problem is I told you, either we can use Vector who stole the data 77 00:05:37,820 --> 00:05:39,800 or we can use it to store the data. 78 00:05:39,890 --> 00:05:40,730 It is our choice. 79 00:05:41,030 --> 00:05:42,320 So now let us use a. 80 00:05:43,320 --> 00:05:44,070 Let's use that. 81 00:05:44,610 --> 00:05:46,140 We see how we can use vector. 82 00:05:46,170 --> 00:05:47,790 So now let us also use Eddie. 83 00:05:49,750 --> 00:05:51,220 So let's create another function. 84 00:05:53,840 --> 00:05:55,550 Control and control. 85 00:05:56,270 --> 00:06:00,710 So this time I will not take the president, but I will take that as input. 86 00:06:01,770 --> 00:06:03,420 I was told the output inside the. 87 00:06:04,290 --> 00:06:07,170 So the name of the ad is output very. 88 00:06:09,660 --> 00:06:16,020 OK, so you are pushing the element now how we can push element inside the output area, so we're pushing 89 00:06:16,020 --> 00:06:20,920 the element inside the area to take when it looks at what next, you need to push the element. 90 00:06:21,240 --> 00:06:22,580 So I'm taking the Next G. 91 00:06:22,980 --> 00:06:24,950 So this Next G will start from zero. 92 00:06:25,110 --> 00:06:26,930 And the next is for output three. 93 00:06:28,090 --> 00:06:37,090 So I want to insert my element, I want to insert my element at the Next G, so output, so output of 94 00:06:37,090 --> 00:06:37,450 G. 95 00:06:38,420 --> 00:06:40,550 It's a simple. 96 00:06:43,190 --> 00:06:47,600 And then to do so, you have to call this function, save all position. 97 00:06:49,670 --> 00:06:51,380 So let's Nimmitabel position. 98 00:06:52,360 --> 00:06:54,070 Using Adi. 99 00:06:55,430 --> 00:06:58,010 So let's copy the function table position using Eddie. 100 00:07:03,720 --> 00:07:10,230 So I am calling the function stable position instead of I said I have output vector and I need to give 101 00:07:10,230 --> 00:07:13,230 J plus one, but I think this is wrong. 102 00:07:13,680 --> 00:07:14,420 Why it is wrong. 103 00:07:14,460 --> 00:07:16,880 See, I need to write one more call here. 104 00:07:17,700 --> 00:07:24,510 So if you are storing the answer, invariably, then you need to pass J plus one simple. 105 00:07:24,780 --> 00:07:25,980 You are passing J plus one. 106 00:07:26,160 --> 00:07:29,100 But when you are not storing the output then you need to pass. 107 00:07:30,180 --> 00:07:34,260 OK, sometimes we need to pass g sometimes we need to pass J plus one. 108 00:07:35,590 --> 00:07:41,380 So I need to write one more call here, so here I am not interrupting anything, R.G.. 109 00:07:42,490 --> 00:07:49,540 So if I didn't Next X is not present, then I will pass only no changes, but in fact I am the next 110 00:07:49,840 --> 00:07:50,230 president. 111 00:07:50,230 --> 00:07:54,260 So I mean, starting next year, I starting next I the next year. 112 00:07:54,280 --> 00:07:56,440 So now I need to call this function. 113 00:07:58,750 --> 00:08:06,610 And I will pass at a number of elements X I plus one, obviously, and now G plus one. 114 00:08:08,990 --> 00:08:15,540 So you need Jay here and you need a plus one here, OK, you know, Vijaya plus one because at the Next 115 00:08:15,540 --> 00:08:18,710 G, you're inserting this element simple. 116 00:08:20,640 --> 00:08:26,190 So now I think our function will work fine, so let's test our function, so let's give a line here. 117 00:08:29,490 --> 00:08:36,000 So let's create an output area and let's say the size is Ben, I'm creating an output aerial system 118 00:08:37,530 --> 00:08:38,909 and let's call this function. 119 00:08:42,490 --> 00:08:44,470 See oil pollution using it. 120 00:08:44,620 --> 00:08:48,250 I will give that as input number of elements is basically six. 121 00:08:49,780 --> 00:08:52,000 The value of, let's say, five. 122 00:08:53,080 --> 00:08:54,530 I will start from zero. 123 00:08:55,120 --> 00:09:01,830 I need to parse the output today, so output, Terry and I need to pass the next four output. 124 00:09:02,740 --> 00:09:08,370 So for next year, I will start pushing from zero in at the start from zero. 125 00:09:08,380 --> 00:09:10,550 And I think our function will work fine. 126 00:09:10,750 --> 00:09:16,510 So all the elements, all the values will be inserted inside our output very fine. 127 00:09:17,530 --> 00:09:25,720 So when thing see here we are passing vector Bio-Reference because by default that are passed by value. 128 00:09:26,350 --> 00:09:29,230 But we know it is passed by reference always. 129 00:09:30,620 --> 00:09:32,490 So I think our function will work. 130 00:09:33,170 --> 00:09:36,330 So now the question is how we can print our output very. 131 00:09:37,610 --> 00:09:44,660 So footprinting, if you want to paint, if you want to paint a picture, you can paint it like this, 132 00:09:44,660 --> 00:09:48,450 you have Daudzai function, but not if I want to print my output. 133 00:09:49,640 --> 00:09:51,290 So how can I bring to my output? 134 00:09:52,010 --> 00:10:00,440 So I used to print an array like this equals zero iList and I plus plus so and I don't know what is. 135 00:10:00,450 --> 00:10:06,860 And so I don't know how many elements are present inside of my output that I cannot write down here. 136 00:10:06,860 --> 00:10:09,730 I cannot write a list and then that will be wrong. 137 00:10:10,670 --> 00:10:17,630 So five president, only three times, so first he will be occupied, firstly, positions will be occupied 138 00:10:17,630 --> 00:10:19,340 first and second and third question. 139 00:10:19,580 --> 00:10:22,010 All the rest will be garbage. 140 00:10:22,460 --> 00:10:23,680 So I cannot use 10. 141 00:10:24,410 --> 00:10:29,030 So how to find out how many elements I have inserted inside my area. 142 00:10:30,140 --> 00:10:31,400 So how we can find that. 143 00:10:33,000 --> 00:10:36,660 So if you remember, we have sort of count occurrence. 144 00:10:38,260 --> 00:10:44,080 We have civil discourse in Congress, so what you can do, I can call the function Congress and it will 145 00:10:44,080 --> 00:10:46,590 give me how many times five is appearing. 146 00:10:46,780 --> 00:10:49,030 So it will give me five is appearing three times. 147 00:10:49,300 --> 00:10:53,530 So I know that my vector is containing three indexes. 148 00:10:53,740 --> 00:10:55,990 So instead of and what can I do? 149 00:10:55,990 --> 00:10:57,700 I can use countercurrent. 150 00:10:59,330 --> 00:10:59,840 Simply. 151 00:11:01,570 --> 00:11:03,230 So I can use countercurrent. 152 00:11:04,150 --> 00:11:10,540 OK, so what will do so let's change the return type of the function so dysfunctional, done integer. 153 00:11:11,630 --> 00:11:14,750 Integer means it will return how many times the element is present. 154 00:11:15,140 --> 00:11:16,760 So instead of calling this function. 155 00:11:17,830 --> 00:11:19,990 I will call return one plus. 156 00:11:20,930 --> 00:11:28,910 And here I will return zero plus, and here I will return zero, so I am doing two things. 157 00:11:29,660 --> 00:11:35,510 I am doing two things with this function, I'm storing the output, I am storing the output, and for 158 00:11:35,510 --> 00:11:36,290 storing the output. 159 00:11:36,290 --> 00:11:38,660 I am taking an output it as well as the index. 160 00:11:39,020 --> 00:11:41,750 So this is the output array and this is the index. 161 00:11:41,750 --> 00:11:43,340 The value of the will start from zero. 162 00:11:43,970 --> 00:11:45,350 So I'm inserting the element. 163 00:11:45,710 --> 00:11:48,700 So I need to write output here, output, energy plus one. 164 00:11:49,670 --> 00:11:55,930 And this function is doing one more thing and that thing is basically count count occurrence. 165 00:11:57,170 --> 00:12:04,970 So if I it is in return zero, if X is present at the next high return one plus otherwise done zero 166 00:12:04,970 --> 00:12:05,300 plus. 167 00:12:05,880 --> 00:12:12,140 So, so this function will return how many times the value is present inside the array. 168 00:12:12,590 --> 00:12:14,210 So I need to write output here. 169 00:12:17,470 --> 00:12:21,580 OK, so this function will return the count. 170 00:12:22,660 --> 00:12:27,730 COUNTERCURRENT, how many times the element is present, so let's simply name it count. 171 00:12:28,890 --> 00:12:29,670 And now. 172 00:12:30,870 --> 00:12:31,760 We can print our. 173 00:12:33,070 --> 00:12:36,370 So I equals zero, I didn't count. 174 00:12:38,100 --> 00:12:39,060 I placeless. 175 00:12:41,540 --> 00:12:42,170 Setout. 176 00:12:44,200 --> 00:12:44,890 Output of. 177 00:12:47,160 --> 00:12:54,420 So what I'm doing here is so I told you I had to bring to my area, my area is of size 10, but only 178 00:12:54,420 --> 00:12:55,320 the three values. 179 00:12:55,620 --> 00:12:58,580 But FIFA's president only three times, so zero one. 180 00:12:58,590 --> 00:13:00,300 And this is three. 181 00:13:00,510 --> 00:13:01,620 So zero is president there. 182 00:13:01,630 --> 00:13:04,350 One is president there and three is presented at all. 183 00:13:04,350 --> 00:13:05,220 Values are garbage. 184 00:13:05,430 --> 00:13:10,620 So I cannot bring to my area like this and I equals zero, i.e. less than 10. 185 00:13:10,620 --> 00:13:15,270 I cannot righton if my size of the arrest and so I cannot return here. 186 00:13:15,450 --> 00:13:16,650 I need to write three. 187 00:13:16,860 --> 00:13:17,730 And what is three. 188 00:13:18,480 --> 00:13:20,580 The number of times is present. 189 00:13:20,730 --> 00:13:23,760 So in vector we have the function so it will give me three. 190 00:13:24,420 --> 00:13:26,440 But in it if we do not have to use function. 191 00:13:26,760 --> 00:13:31,920 So if you remember, we have written the code for count occurrence function. 192 00:13:33,400 --> 00:13:39,840 And how does condo construction work so they will be integer eight zero from here if you find the value 193 00:13:39,880 --> 00:13:44,360 it used to call one plus recursion and it used to call zero plus equation. 194 00:13:44,620 --> 00:13:51,790 So this function has all the properties of countercurrent, so this function will return three. 195 00:13:52,420 --> 00:13:56,610 So I am storing that in this variable three and I'm using three here. 196 00:13:57,370 --> 00:13:58,750 So that's how it will work. 197 00:13:58,780 --> 00:14:04,930 OK, so this function is working exactly like countercurrent function, but it is also storing the output 198 00:14:04,930 --> 00:14:05,200 here. 199 00:14:06,190 --> 00:14:09,100 Simple, so now let us test our function. 200 00:14:16,310 --> 00:14:18,380 OK, so what is happening here? 201 00:14:18,590 --> 00:14:24,850 So this is this was about three, five, five, six, five, six and seven. 202 00:14:25,250 --> 00:14:28,940 So first I am painting director but I'm giving 10. 203 00:14:28,940 --> 00:14:30,050 So 10 is not pleasant. 204 00:14:30,060 --> 00:14:30,920 And so I decided. 205 00:14:30,920 --> 00:14:35,010 So I will not print anything, which is basically zero zero deadline. 206 00:14:35,240 --> 00:14:36,390 So go to the next line. 207 00:14:37,310 --> 00:14:44,180 So after reaching the next line, if you see that we are searching for data five, data five is present 208 00:14:44,180 --> 00:14:47,030 at index zero at the next one at the next three. 209 00:14:47,420 --> 00:14:52,840 And we are printing and then we are giving and line so it zero and next one and next three. 210 00:14:53,090 --> 00:14:56,870 So we are giving and that's why the output is coming out in different lines. 211 00:14:59,350 --> 00:15:01,710 So let's test our function one more time. 212 00:15:04,870 --> 00:15:06,910 So let's give Speciate. 213 00:15:09,120 --> 00:15:13,890 And let's say I want to search for sex success the next to and for. 214 00:15:15,440 --> 00:15:16,370 So 24. 215 00:15:19,360 --> 00:15:21,670 Seven, OK, so I need to give seven. 216 00:15:23,070 --> 00:15:24,300 I am testing for seven. 217 00:15:25,360 --> 00:15:28,540 So when is the next five, so five is the output. 218 00:15:29,440 --> 00:15:33,330 And let's test it one more time then, is not present inside the area. 219 00:15:33,820 --> 00:15:39,610 So basically the value count will be zero and I will not go inside this for loop, so I will not print 220 00:15:39,610 --> 00:15:40,030 anything. 221 00:15:40,780 --> 00:15:42,130 So I am not printing anything. 222 00:15:45,190 --> 00:15:47,890 So this is how you can write the code. 223 00:15:47,920 --> 00:15:49,970 OK, so this is it from this video. 224 00:15:50,020 --> 00:15:51,190 I will see you in the next one.