1 00:00:07,350 --> 00:00:09,720 How did you do while completing the assignment? 2 00:00:10,380 --> 00:00:16,530 Hopefully you were able to successfully complete it and we're able to troubleshoot any potential issues 3 00:00:16,530 --> 00:00:17,490 you might have had. 4 00:00:17,850 --> 00:00:22,470 In this lecture, we are going to go over my solution to the assignment. 5 00:00:23,280 --> 00:00:28,560 The first thing that I want to do is I want to go ahead and create my function and I know it's going 6 00:00:28,560 --> 00:00:29,550 to take an array. 7 00:00:29,550 --> 00:00:33,480 So we'll just go ahead and give it a vector of eight. 8 00:00:33,600 --> 00:00:37,590 And then I also know that I'm going to want to know the size of the array. 9 00:00:37,590 --> 00:00:39,750 So we'll give it my size as well. 10 00:00:40,560 --> 00:00:46,320 And then if the size is less than one, then we won't really have anything to do because then that will 11 00:00:46,320 --> 00:00:48,300 be the sum of the array. 12 00:00:49,110 --> 00:00:54,690 We also knew from the instructions that we're going to want a temporary array, that we're going to 13 00:00:54,690 --> 00:00:59,340 store the values in, which means that we want it to be mutable. 14 00:01:00,390 --> 00:01:08,010 And since it's going to be an empty array, I'm just going to go ahead and just say Vic Nu, and we 15 00:01:08,010 --> 00:01:13,590 know that we're going to pass this temporary array back into our function. 16 00:01:13,710 --> 00:01:18,330 So now I want to just go ahead and I want to make this a mutable reference. 17 00:01:20,830 --> 00:01:28,140 And now we can begin adding in consecutive elements and storing them into our temp array. 18 00:01:28,150 --> 00:01:34,180 So I'll say four I in zero to size minus one. 19 00:01:36,070 --> 00:01:46,990 We want to say let x equals array of I plus array of I plus one, because now we're getting the consecutive 20 00:01:46,990 --> 00:01:55,720 elements in the array and then we want to push the result of that addition onto our temporary array. 21 00:01:57,520 --> 00:02:03,610 And then once we have done that, we want to be able to print out our array when we are backtracking, 22 00:02:06,040 --> 00:02:11,650 aka unwinding the stack, and then we can simply just say, print out the array. 23 00:02:14,400 --> 00:02:15,300 So now. 24 00:02:16,190 --> 00:02:17,930 We can call our function. 25 00:02:18,170 --> 00:02:24,590 But first we need to create our vector and I'll use the VC macro for quick initialization. 26 00:02:24,590 --> 00:02:27,530 So we'll have one, two, three, four and five. 27 00:02:27,590 --> 00:02:34,220 That way it lines up with what we discussed when we were talking about this problem in the previous 28 00:02:34,220 --> 00:02:46,340 lecture and we will say let's size equal to VEC dot link and now we can call our function and we will 29 00:02:46,340 --> 00:02:51,530 pass it in as immutable reference to our VEC and then we will also pass in size. 30 00:02:52,220 --> 00:02:55,730 So let's double check this real quick to make sure everything lines up. 31 00:02:57,470 --> 00:03:01,340 We're passing in our our vector of integers. 32 00:03:01,580 --> 00:03:07,610 We do our base case so that if our size is less than one, we return. 33 00:03:08,760 --> 00:03:18,360 We create our temporary vector to store our consecutive editions from the array that is passed in as 34 00:03:18,360 --> 00:03:23,760 the parameter, and we push that value onto the temporary array. 35 00:03:24,930 --> 00:03:27,960 And I forgot one very important step. 36 00:03:27,980 --> 00:03:29,460 I'm glad we went over this. 37 00:03:29,850 --> 00:03:32,430 I need to make my recursive call. 38 00:03:33,600 --> 00:03:43,290 So in here we're going to pass in the temporary that we created, and our size is now going to be size 39 00:03:43,290 --> 00:03:44,430 minus one. 40 00:03:45,750 --> 00:03:48,240 So now everything is looking really good. 41 00:03:48,240 --> 00:03:49,980 So let's go ahead and run this. 42 00:03:50,670 --> 00:04:00,210 And we see that we have 48, 20 and 28, eight, 12, 16, three, five, seven, nine, one, two, 43 00:04:00,210 --> 00:04:01,590 three, four, five. 44 00:04:01,890 --> 00:04:04,050 And that is the correct output. 45 00:04:04,050 --> 00:04:08,310 And we did this while executing a recursive, recursive approach. 46 00:04:08,400 --> 00:04:11,490 So hopefully you were able to get to this solution. 47 00:04:11,490 --> 00:04:18,090 It might not be the same as mine, but hopefully your solution used recursion and you were able to get 48 00:04:18,090 --> 00:04:20,010 to the same output as I was. 49 00:04:20,550 --> 00:04:26,160 If you have any questions regarding my solution to this assignment, please feel free to ask them in 50 00:04:26,160 --> 00:04:27,510 the Q&A section. 51 00:04:28,680 --> 00:04:33,210 So hopefully you enjoyed this assignment and I will see you in the next section.