1 00:00:00,000 --> 00:00:08,533 [No Audio] 2 00:00:08,534 --> 00:00:10,900 Hello and welcome back again. The 3 00:00:10,901 --> 00:00:13,500 objective in this and some of the upcoming 4 00:00:13,501 --> 00:00:15,600 tutorials is, to give you some practice of 5 00:00:15,601 --> 00:00:17,433 coding in Rust by applying what we have 6 00:00:17,434 --> 00:00:19,833 learned so far. While doing this, we will 7 00:00:19,834 --> 00:00:21,766 have a chance of learning frequently used 8 00:00:21,767 --> 00:00:23,900 data structure called stack. More 9 00:00:23,901 --> 00:00:26,400 specifically, it is an abstract data type or 10 00:00:26,401 --> 00:00:29,300 ADT, commonly used in most programming 11 00:00:29,301 --> 00:00:32,266 languages. It is named stack as it behaves 12 00:00:32,267 --> 00:00:34,433 like a real world stack, for example, a deck 13 00:00:34,434 --> 00:00:37,400 of cards or a pile of plates. A real world 14 00:00:37,401 --> 00:00:40,066 stack allows operations at one end only, for 15 00:00:40,067 --> 00:00:43,066 example, we can place or move a card or plate 16 00:00:43,067 --> 00:00:46,100 from the top of the stack only. Likewise, the 17 00:00:46,101 --> 00:00:48,733 stack abstract data type allows all data 18 00:00:48,734 --> 00:00:51,733 operations at one end only. At any given time, 19 00:00:51,734 --> 00:00:54,100 we can only access the top element of a stack. 20 00:00:54,233 --> 00:00:57,133 This feature makes it behaves in a manner 21 00:00:57,134 --> 00:01:00,166 that last element in is always the first one 22 00:01:00,167 --> 00:01:03,100 to get out. This is sometimes referred to as 23 00:01:03,101 --> 00:01:06,266 LIFO for short, that is Last In First Out. 24 00:01:06,666 --> 00:01:08,766 There are two key terminologies that are 25 00:01:08,767 --> 00:01:10,800 being used in connection with the stack, that 26 00:01:10,801 --> 00:01:14,666 are called push and pop. In fact, these 27 00:01:14,667 --> 00:01:16,533 are operations that are being performed on 28 00:01:16,534 --> 00:01:18,833 the stack. The push operation is used to 29 00:01:18,834 --> 00:01:21,600 insert on, or add in element at the top of the 30 00:01:21,601 --> 00:01:23,400 stack, and the pop is used to remove an 31 00:01:23,401 --> 00:01:26,100 element from the top of the stack. Some 32 00:01:26,101 --> 00:01:28,833 simple applications of stack include string 33 00:01:28,834 --> 00:01:30,766 traversal, expression evaluation, 34 00:01:30,767 --> 00:01:33,466 backtracking, and syntax parsing. This 35 00:01:33,467 --> 00:01:35,600 visualization explains the key concepts of 36 00:01:35,601 --> 00:01:38,400 stack. Initially, we have an empty stack with 37 00:01:38,401 --> 00:01:41,533 no top element, and insert a value of 10 into 38 00:01:41,534 --> 00:01:44,100 the stack, the top of the stack element is 39 00:01:44,101 --> 00:01:47,600 now, has now the value of 10. Next we add 40 00:01:47,601 --> 00:01:49,700 another element in the stack using a push 41 00:01:49,701 --> 00:01:52,700 operation. And the new value of 20 which is 42 00:01:52,701 --> 00:01:55,500 being pushed, is now the new top of the stack. 43 00:01:56,000 --> 00:01:57,800 Next to push another element with the value 44 00:01:57,801 --> 00:02:01,066 of 30, which is the new top of the stack, the 45 00:02:01,067 --> 00:02:03,266 pop operation will remove the top of the 46 00:02:03,267 --> 00:02:06,300 stack element from the stack. So when the top 47 00:02:06,301 --> 00:02:08,265 of the stack element is being removed, the 48 00:02:08,266 --> 00:02:11,266 new top of the stack will become 20. This way 49 00:02:11,267 --> 00:02:13,766 the stack ensures that the element which is, 50 00:02:13,800 --> 00:02:16,700 which is first being pushed is always the last one 51 00:02:16,701 --> 00:02:18,866 which is going to be out from the stack. 52 00:02:20,600 --> 00:02:22,566 There is also a very nice online 53 00:02:22,567 --> 00:02:25,500 visualization of stack, let me open it. There 54 00:02:25,501 --> 00:02:27,366 are two operations that we can perform on the 55 00:02:27,367 --> 00:02:29,900 stack, typically during implementation we 56 00:02:29,901 --> 00:02:32,366 will have a fixed size of the stack. 57 00:02:32,400 --> 00:02:34,733 These small boxes represents the elements 58 00:02:34,734 --> 00:02:37,566 of the stack, which are all initially empty. 59 00:02:38,233 --> 00:02:41,100 And let us add a few elements to the stack. I 60 00:02:41,101 --> 00:02:44,333 will add a value of 30, followed by 15, and then 36. 61 00:02:44,334 --> 00:02:46,833 [No Audio] 62 00:02:46,834 --> 00:02:48,766 You may note that each time I add an 63 00:02:48,800 --> 00:02:50,933 element, it is being added to the front of the 64 00:02:50,934 --> 00:02:53,566 stack. You may consider this tag to be a 65 00:02:53,567 --> 00:02:57,100 stack which is horizontal in direction. The 66 00:02:57,101 --> 00:02:59,533 elements at the front are the top of the 67 00:02:59,534 --> 00:03:03,266 stack elements. Let me do a pop and you may 68 00:03:03,267 --> 00:03:05,533 note that the element from the front, which 69 00:03:05,534 --> 00:03:07,366 represents the top of the stack, are being 70 00:03:07,367 --> 00:03:10,833 removed. This visualization is helpful from 71 00:03:10,834 --> 00:03:12,666 programming perspective, because in 72 00:03:12,667 --> 00:03:15,200 programmatic implementation or in code, we 73 00:03:15,201 --> 00:03:17,866 will encounter such horizontal implementation 74 00:03:17,867 --> 00:03:21,000 of stack. Okay, now it's time to implement 75 00:03:21,001 --> 00:03:24,166 the stack in Rust. So I will open up the VS Code. 76 00:03:24,167 --> 00:03:26,166 The first thing to note is that, in Rust 77 00:03:26,167 --> 00:03:27,933 there are many useful collections which 78 00:03:27,934 --> 00:03:30,566 provides behavior and functionality similar 79 00:03:30,567 --> 00:03:32,700 to that of a stack, and other important 80 00:03:32,701 --> 00:03:34,866 abstract data types, such as heaps and linked 81 00:03:34,867 --> 00:03:38,433 lists. All we need to do is to have some 82 00:03:38,434 --> 00:03:40,500 wrapping around these beautifully designed 83 00:03:40,501 --> 00:03:42,266 collections to implement the desired 84 00:03:42,267 --> 00:03:45,000 functionality. The stack can be implemented 85 00:03:45,001 --> 00:03:47,300 using vectors, simple arrays, the linked 86 00:03:47,301 --> 00:03:50,500 lists, or vecdeque types. Since the objective in 87 00:03:50,501 --> 00:03:52,933 these tutorials is to practice what we have 88 00:03:52,934 --> 00:03:54,866 learned so far, so we will therefore use the 89 00:03:54,867 --> 00:03:56,666 Vec type for implementing the stack. 90 00:03:57,800 --> 00:04:00,766 I'm considering to implement a stack of u32 91 00:04:00,767 --> 00:04:03,600 values. To start with, we will first define a 92 00:04:03,601 --> 00:04:06,366 function called new_stack, this 93 00:04:06,367 --> 00:04:08,400 function will receive an input of maxsize 94 00:04:08,401 --> 00:04:10,866 which indicates how much space we need to 95 00:04:10,867 --> 00:04:12,900 have in the stack, and then it will create a 96 00:04:12,901 --> 00:04:16,733 new stack, and then we will, we will return that stack. 97 00:04:16,734 --> 00:04:24,433 [No Audio] 98 00:04:24,434 --> 00:04:26,866 Please note that the maxsize needs to be of 99 00:04:26,867 --> 00:04:29,533 usize, because the size of the Vec needs to 100 00:04:29,534 --> 00:04:32,500 be specified as usize type. The 101 00:04:32,501 --> 00:04:35,400 with::capacity is a function, which is 102 00:04:35,401 --> 00:04:37,900 used to create a vector with some predefined, 103 00:04:37,901 --> 00:04:40,233 or some specified number of elements. This 104 00:04:40,234 --> 00:04:42,300 function was covered in the earlier tutorials 105 00:04:42,301 --> 00:04:45,533 also. Next we are going to define the pop 106 00:04:45,534 --> 00:04:47,733 function. This function is going to remove the 107 00:04:47,734 --> 00:04:49,600 topmost element from the stack, and will 108 00:04:49,601 --> 00:04:52,200 display its value to the user. If the stack 109 00:04:52,201 --> 00:04:54,200 is empty, then in this case this function 110 00:04:54,201 --> 00:04:56,733 should return a none or no value. I will 111 00:04:56,734 --> 00:04:59,166 declare the function pop and will provide a 112 00:04:59,167 --> 00:05:01,333 mutable reference to the back as an input. 113 00:05:01,334 --> 00:05:06,433 [No Audio] 114 00:05:06,434 --> 00:05:08,133 Now this is because the function is supposed 115 00:05:08,134 --> 00:05:10,766 to remove an element from that from the stack, 116 00:05:10,767 --> 00:05:12,900 which means, we will be modifying the stack. 117 00:05:13,533 --> 00:05:15,433 The output of the function will be an 118 00:05:15,434 --> 00:05:18,333 optional u32 value, the option type 119 00:05:18,334 --> 00:05:20,366 represents either some value, if the value 120 00:05:20,367 --> 00:05:23,300 exists, or none value if the value, if there is 121 00:05:23,301 --> 00:05:27,466 no value. Inside the function, I will declare a 122 00:05:27,467 --> 00:05:29,500 variable called popped value, which will 123 00:05:29,501 --> 00:05:31,866 store the result of pop operation on the stack. 124 00:05:31,867 --> 00:05:34,933 [No Audio] 125 00:05:34,934 --> 00:05:36,933 This will essentially remove the top 126 00:05:36,934 --> 00:05:40,400 element from the back. Next, I will include, I 127 00:05:40,401 --> 00:05:42,333 will include a print statement to display the 128 00:05:42,334 --> 00:05:43,900 contents of the poped value. 129 00:05:43,901 --> 00:05:49,166 [No Audio] 130 00:05:49,167 --> 00:05:51,600 Finally, I will return the poped_val, 131 00:05:51,601 --> 00:05:53,433 so I will write popped_val 132 00:05:53,434 --> 00:05:58,366 without the semicolon. Next, the next 133 00:05:58,367 --> 00:06:00,166 function we will implement is, the push 134 00:06:00,167 --> 00:06:02,100 function, which will add the given value to 135 00:06:02,101 --> 00:06:05,133 the top of the stack, so, let us declare the push function. 136 00:06:05,134 --> 00:06:07,433 [No Audio] 137 00:06:07,434 --> 00:06:10,366 The input will be a mutable reference to the stack. 138 00:06:10,367 --> 00:06:12,633 [No Audio] 139 00:06:12,634 --> 00:06:13,800 Please note that we should 140 00:06:13,801 --> 00:06:15,300 be using a reference in all the 141 00:06:15,301 --> 00:06:17,333 functions, because we do not want to take the 142 00:06:17,334 --> 00:06:19,900 ownership of the stack, but rather we just 143 00:06:19,901 --> 00:06:22,866 want to add an element to the stack. In 144 00:06:22,867 --> 00:06:24,933 addition to the mutable reference to the stack, 145 00:06:24,934 --> 00:06:27,800 we also need the item or number that 146 00:06:27,801 --> 00:06:31,000 we want to add to the stack, so, let me mention that also. 147 00:06:31,001 --> 00:06:33,466 [No Audio] 148 00:06:33,467 --> 00:06:35,100 Finally, I will also need 149 00:06:35,101 --> 00:06:37,633 a third input, which is the size of the stack. 150 00:06:37,766 --> 00:06:39,900 This will be used to check if the maxsize is 151 00:06:39,901 --> 00:06:42,500 reached or not, we will not allow further 152 00:06:42,501 --> 00:06:44,400 elements to be added, if we have reached the 153 00:06:44,401 --> 00:06:47,366 maxsize. This function is not going to return 154 00:06:47,367 --> 00:06:50,266 anything. Inside the function, I will check if 155 00:06:50,267 --> 00:06:52,300 the current length of the stack is equal to 156 00:06:52,301 --> 00:06:53,900 that of the maxsize or not. 157 00:06:53,901 --> 00:07:00,266 [No Audio] 158 00:07:00,267 --> 00:07:02,333 In this case, I should not be adding any 159 00:07:02,334 --> 00:07:04,233 further elements, therefore, I will display 160 00:07:04,234 --> 00:07:06,533 the message of cannot add more. 161 00:07:06,534 --> 00:07:14,466 [No Audio] 162 00:07:14,467 --> 00:07:17,333 If however, this is not true, then I will 163 00:07:17,334 --> 00:07:19,433 continue with adding the given item to the 164 00:07:19,434 --> 00:07:21,433 top of the stack using the push function. 165 00:07:21,434 --> 00:07:27,733 [No Audio] 166 00:07:27,734 --> 00:07:30,100 I will also display the contents of the stack. 167 00:07:30,101 --> 00:07:35,700 [No Audio] 168 00:07:35,701 --> 00:07:37,600 I will add one more simple function, which is 169 00:07:37,601 --> 00:07:39,600 going to return the current size of the stack 170 00:07:39,833 --> 00:07:43,200 I will declare this function with the name of size. 171 00:07:44,433 --> 00:07:47,000 The input, in this case, will be a, will be 172 00:07:47,001 --> 00:07:49,466 an immutable reference to the stack, since we 173 00:07:49,467 --> 00:07:51,466 are not modifying the stack and the output 174 00:07:51,467 --> 00:07:54,426 will be the size of the stack which is of type usize. 175 00:07:54,427 --> 00:07:59,766 [No Audio] 176 00:07:59,767 --> 00:08:02,066 Inside the function, I will use the length 177 00:08:02,067 --> 00:08:05,300 function on the stack, which will return the size. 178 00:08:05,301 --> 00:08:10,066 [No Audio] 179 00:08:10,067 --> 00:08:12,166 Okay great, we are almost done with the 180 00:08:12,167 --> 00:08:14,100 stack implementation. Now, let us add some 181 00:08:14,101 --> 00:08:16,800 code in the main function. In the main 182 00:08:16,801 --> 00:08:19,600 function, first I will ask the user to tell me 183 00:08:19,601 --> 00:08:21,433 the number of elements he wants to have in 184 00:08:21,434 --> 00:08:23,966 the stack. So, I will add a suitable print 185 00:08:23,967 --> 00:08:25,366 statement for this purpose. 186 00:08:25,367 --> 00:08:33,133 [No Audio] 187 00:08:33,134 --> 00:08:34,933 Next, I will write the code for taking the 188 00:08:34,934 --> 00:08:37,033 user input, and I will store the input in the 189 00:08:37,034 --> 00:08:38,832 variable of size_stack. 190 00:08:38,833 --> 00:08:44,933 [No Audio] 191 00:08:44,934 --> 00:08:47,200 As I will be using the code for taking the 192 00:08:47,201 --> 00:08:49,633 user input many times, for tasks such as 193 00:08:49,634 --> 00:08:52,466 selecting operation types such as, push, pop, 194 00:08:52,500 --> 00:08:54,500 and for mentioning the item that the user 195 00:08:54,501 --> 00:08:56,500 wants to push. So therefore, it is more 196 00:08:56,501 --> 00:08:58,500 appropriate to have some function which will 197 00:08:58,501 --> 00:09:01,333 contain the code for taking the user input. I 198 00:09:01,334 --> 00:09:03,100 will declare the function with the name of 199 00:09:03,101 --> 00:09:05,266 input this function will have no input, and 200 00:09:05,267 --> 00:09:07,133 the output will be the values that are being 201 00:09:07,134 --> 00:09:09,566 provided as input by the user. Now since we 202 00:09:09,567 --> 00:09:11,633 are dealing mainly with the u32 type, 203 00:09:11,634 --> 00:09:13,600 so I am expecting the input to be of type 204 00:09:13,601 --> 00:09:16,333 u32. Therefore for the output type, I will 205 00:09:16,334 --> 00:09:19,100 mention u32. Inside the body of the 206 00:09:19,101 --> 00:09:20,966 function, I will write the code for taking the 207 00:09:20,967 --> 00:09:23,978 user input which we covered in the previous sections. 208 00:09:23,979 --> 00:09:34,900 [No Audio] 209 00:09:34,901 --> 00:09:36,433 I will write the code for converting 210 00:09:36,434 --> 00:09:39,333 the input to u32 using the parse function. 211 00:09:39,334 --> 00:09:42,533 [No Audio] 212 00:09:42,534 --> 00:09:43,933 Finally I will return the 213 00:09:43,934 --> 00:09:46,200 input. Inside the main function, I will use 214 00:09:46,201 --> 00:09:48,200 this function to have user input regarding 215 00:09:48,201 --> 00:09:49,266 the size of the stack. 216 00:09:49,267 --> 00:09:53,700 [No Audio] 217 00:09:53,701 --> 00:09:55,933 Next, I will call the new_stack function 218 00:09:55,934 --> 00:09:57,133 to create the stack. 219 00:09:57,134 --> 00:10:02,866 [No Audio] 220 00:10:02,867 --> 00:10:04,833 Please note that, since I will be adding 221 00:10:04,834 --> 00:10:07,000 elements and deleting elements from the stack, 222 00:10:07,001 --> 00:10:10,366 therefore I need to declare it as mutable, 223 00:10:10,367 --> 00:10:12,333 and secondly, the size of the stack needs to 224 00:10:12,334 --> 00:10:14,400 be mentioned as usize. So therefore, I 225 00:10:14,401 --> 00:10:16,933 will convert the u32 to usize. 226 00:10:17,000 --> 00:10:19,633 And next, I will display a menu to the user, from 227 00:10:19,634 --> 00:10:21,633 which he can select one of the available 228 00:10:21,634 --> 00:10:22,933 options on the stack. 229 00:10:22,934 --> 00:10:29,300 [No Audio] 230 00:10:29,301 --> 00:10:31,200 Again, for grabbing and storing the user 231 00:10:31,201 --> 00:10:33,300 choice, we will call the input function, and 232 00:10:33,301 --> 00:10:35,900 will storage result in the variable choice. 233 00:10:35,901 --> 00:10:42,233 [No Audio] 234 00:10:42,234 --> 00:10:44,266 Next, I will use a match statement to see 235 00:10:44,267 --> 00:10:46,866 which choice is being selected, and 236 00:10:46,867 --> 00:10:50,133 will make appropriate function calls. I will 237 00:10:50,134 --> 00:10:52,700 do a match on the choice variable for this purpose. 238 00:10:52,701 --> 00:10:56,866 [No Audio] 239 00:10:56,867 --> 00:10:58,700 Next, I will mention the arms 240 00:10:58,701 --> 00:11:00,900 corresponding to different choices. In case 241 00:11:00,901 --> 00:11:03,033 the choice is one, so I will push an element 242 00:11:03,034 --> 00:11:05,700 onto the stack. Let me add the arm 243 00:11:05,701 --> 00:11:08,200 corresponding to first choice. In this case, 244 00:11:08,201 --> 00:11:10,800 I will ask the user for the item that he 245 00:11:10,801 --> 00:11:14,033 wants to insert into the stack. I will take 246 00:11:14,034 --> 00:11:16,066 the input from the user and we'll store it in 247 00:11:16,067 --> 00:11:17,300 a variable of item. 248 00:11:17,301 --> 00:11:19,800 [No Audio] 249 00:11:19,801 --> 00:11:21,500 Finally, I will call the push function 250 00:11:21,501 --> 00:11:23,033 to add the element to the stack. 251 00:11:23,400 --> 00:11:25,633 The function needs three inputs, that is the 252 00:11:25,634 --> 00:11:27,866 mutable reference to the stack, the item we 253 00:11:27,867 --> 00:11:32,400 want to insert and the signs. Now let us add 254 00:11:32,401 --> 00:11:34,600 the arm for the second choice. In this case, 255 00:11:34,601 --> 00:11:37,400 I will pop the element from the stack. So I 256 00:11:37,401 --> 00:11:39,166 will call the pop function and we'll display 257 00:11:39,167 --> 00:11:40,933 the element that is being popped out. 258 00:11:40,934 --> 00:11:50,633 [No Audio] 259 00:11:50,634 --> 00:11:53,500 The next arm is for choice 4, in this case, 260 00:11:53,501 --> 00:11:55,566 we will display the sides of the stack, so 261 00:11:55,567 --> 00:11:58,100 let me complete the code for this arm also. 262 00:11:58,101 --> 00:12:06,533 [No Audio] 263 00:12:06,534 --> 00:12:09,166 In case of none, there is none of the above 264 00:12:09,200 --> 00:12:13,533 arm matches, so I will exit. This is going to 265 00:12:13,534 --> 00:12:16,166 be the default arm, so let me include this also. 266 00:12:16,167 --> 00:12:18,766 [No Audio] 267 00:12:18,767 --> 00:12:21,400 Now this code will only allow a single 268 00:12:21,401 --> 00:12:23,766 operation to take place, there is a single pop, 269 00:12:23,800 --> 00:12:26,900 or push, or display. I want the same code to 270 00:12:26,901 --> 00:12:29,200 be repeated multiple times, and when the user 271 00:12:29,201 --> 00:12:31,666 want to exit, so only in that case, I will 272 00:12:31,667 --> 00:12:34,333 break out from the iterations. So to do that, 273 00:12:34,334 --> 00:12:36,800 I will enclose this whole code inside a loop. 274 00:12:36,801 --> 00:12:42,500 [No Audio] 275 00:12:42,501 --> 00:12:44,700 At the end of the loop, I will ask the user 276 00:12:44,701 --> 00:12:47,000 again if he wants to continue or not. So I 277 00:12:47,001 --> 00:12:48,800 will create a suitable print statement and 278 00:12:48,801 --> 00:12:50,733 we'll take the user input, and store it in 279 00:12:50,734 --> 00:12:55,133 some variable, let's say status. Next, I will 280 00:12:55,134 --> 00:12:57,500 add a simple if else statement. In the left 281 00:12:57,501 --> 00:12:59,433 part, I will check if the user wants to 282 00:12:59,434 --> 00:13:01,733 continue with the operations on the stack. So 283 00:13:01,734 --> 00:13:04,333 I will continue with the next iteration of the loop. 284 00:13:04,733 --> 00:13:07,200 In any other case, I will break out from the loop. 285 00:13:09,100 --> 00:13:10,500 Now this code is correct, but 286 00:13:10,501 --> 00:13:12,866 it will be more meaningful if I include the 287 00:13:12,867 --> 00:13:16,200 the if else inside the match, inside the match 288 00:13:16,201 --> 00:13:18,233 statement by adding another arm for the 289 00:13:18,234 --> 00:13:21,300 match. Because the value 5 in our menu 290 00:13:21,301 --> 00:13:24,066 list, corresponds to an exit. So I will write 291 00:13:24,067 --> 00:13:26,066 5 and then a break. 292 00:13:27,533 --> 00:13:29,566 And we'll comment out the print statement. 293 00:13:29,567 --> 00:13:31,633 Finally for the default case, 294 00:13:31,634 --> 00:13:34,033 I will write something like, wrong 295 00:13:34,034 --> 00:13:38,466 selection try again. Ok, and now our code is complete. 296 00:13:39,900 --> 00:13:41,866 Let us execute this program. 297 00:13:41,867 --> 00:13:46,733 [No Audio] 298 00:13:46,734 --> 00:13:49,233 it will ask for the size of the stack, so 299 00:13:49,234 --> 00:13:52,400 let me enter the value of 3. The menu list 300 00:13:52,401 --> 00:13:54,533 has been displayed, let us try to pop 301 00:13:54,534 --> 00:13:57,033 something from the empty stack. The popped 302 00:13:57,034 --> 00:13:59,700 element is none, because we do not have any, 303 00:13:59,733 --> 00:14:02,866 anything to pop. Let us continue again by 304 00:14:02,867 --> 00:14:05,366 selecting 1. This time I will push something 305 00:14:05,367 --> 00:14:08,800 like 56. Let me continue again and push one 306 00:14:08,801 --> 00:14:12,333 more element. At this time I will add the 307 00:14:12,334 --> 00:14:15,800 value of 8. The stack, in this case is in 308 00:14:15,801 --> 00:14:17,766 horizontal direction, and the top of the stack 309 00:14:17,767 --> 00:14:19,833 is indicated by the right-most element. 310 00:14:21,366 --> 00:14:25,000 Let us add one more element. Let us try one more 311 00:14:25,001 --> 00:14:27,566 element, and this should be, and this should not be 312 00:14:27,567 --> 00:14:29,600 possible, because we are at the limit of the 313 00:14:29,601 --> 00:14:32,300 stack. It rightfully says that, we cannot add 314 00:14:32,301 --> 00:14:35,466 more. Let us also test the pop function and 315 00:14:35,467 --> 00:14:38,700 remove one element. The top of the stack is 316 00:14:38,701 --> 00:14:41,366 being removed, the statement contains only 317 00:14:41,367 --> 00:14:44,100 two elements. Before we end, I would like to 318 00:14:44,101 --> 00:14:46,033 highlight the fact that there are many other 319 00:14:46,034 --> 00:14:48,033 efficient ways in which we can implement a 320 00:14:48,034 --> 00:14:50,600 stack using Rust. Using some advanced concepts 321 00:14:50,601 --> 00:14:53,033 such as, generic, structures and others, which 322 00:14:53,034 --> 00:14:55,466 we will cover later on in the course. The 323 00:14:55,467 --> 00:14:57,533 objective however in this implementation was, 324 00:14:57,534 --> 00:14:59,766 to have some practice of the key concepts and 325 00:14:59,767 --> 00:15:01,733 notions that we have learned so far. 326 00:15:02,266 --> 00:15:05,233 Finally there is also more effective and 327 00:15:05,234 --> 00:15:08,033 efficient way of testing our code, which we 328 00:15:08,034 --> 00:15:10,800 will cover later on in the sections. With 329 00:15:10,801 --> 00:15:12,533 this we end this tutorial. In the upcoming 330 00:15:12,534 --> 00:15:14,200 tutorials, we will be looking at some 331 00:15:14,201 --> 00:15:16,100 applications of stack. So do come back for 332 00:15:16,101 --> 00:15:19,288 covering that and until then happy Rust programming. 333 00:15:19,289 --> 00:15:25,500 [No Audio]