1 00:00:06,900 --> 00:00:11,130 In this lecture, we are now going to talk about what a stack is. 2 00:00:11,400 --> 00:00:14,250 And a stack is something that we have been talking about. 3 00:00:14,250 --> 00:00:20,340 If you remember when we would say we would unwind the stack when referring to recursion. 4 00:00:20,670 --> 00:00:26,070 So we were now going to get a better insight as to what a stack actually is. 5 00:00:26,940 --> 00:00:35,160 So the first thing to know about a stack is there's a specific order in which we can insert and remove 6 00:00:35,160 --> 00:00:38,100 elements so specific. 7 00:00:40,240 --> 00:00:44,380 Order in how. 8 00:00:45,720 --> 00:00:48,300 We insert. 9 00:00:50,720 --> 00:00:53,930 And remove. 10 00:00:56,550 --> 00:00:57,200 Elements. 11 00:00:58,740 --> 00:01:07,950 And now this order actually has its own acronym, and it is called LIFO. 12 00:01:09,450 --> 00:01:12,600 And LIFO is last in. 13 00:01:15,590 --> 00:01:18,890 First out. 14 00:01:20,700 --> 00:01:26,550 Meaning we can insert at. 15 00:01:28,070 --> 00:01:28,970 The top. 16 00:01:31,700 --> 00:01:37,940 And then take from the top. 17 00:01:39,080 --> 00:01:41,690 So think of this as a stack of plates. 18 00:01:47,820 --> 00:01:55,710 And I like to think of it as a stack of plates, because when you put plates into the cabinet, if you 19 00:01:55,710 --> 00:02:00,150 add a plate here, well, you're not going to take this plate. 20 00:02:00,780 --> 00:02:04,200 You're going to take the plate that you recently just add it in. 21 00:02:04,440 --> 00:02:06,540 So then you would take that plate. 22 00:02:07,530 --> 00:02:12,180 So last in, first out. 23 00:02:16,080 --> 00:02:20,520 So when we look at a stack, we'll say that this is our stack. 24 00:02:21,570 --> 00:02:25,740 We will say push ten. 25 00:02:26,940 --> 00:02:29,010 Well, now we have ten here. 26 00:02:29,340 --> 00:02:38,400 And then if we push 20 and now we have 20 here, push 30. 27 00:02:39,060 --> 00:02:40,800 Now we have 30 here. 28 00:02:40,920 --> 00:02:43,440 But then if we call Pop. 29 00:02:44,750 --> 00:02:46,280 Now 30 is gone. 30 00:02:47,570 --> 00:02:54,200 And then if we push 40, now 40 is here. 31 00:02:55,430 --> 00:02:59,630 And if we call pop again now 40 is gone. 32 00:03:00,080 --> 00:03:06,200 So this might seem very similar to something that we just did. 33 00:03:06,530 --> 00:03:09,590 So let's just so our stack is here. 34 00:03:12,020 --> 00:03:13,430 Our top is here. 35 00:03:16,210 --> 00:03:18,370 We insert at the top, 36 00:03:21,280 --> 00:03:22,390 we remove. 37 00:03:23,460 --> 00:03:28,470 From the top, so this might seem very familiar. 38 00:03:28,830 --> 00:03:35,520 We just did something like this with our linked list Every time we put in a new value when we called 39 00:03:35,520 --> 00:03:41,010 pop, that latest value that we pushed in was removed. 40 00:03:41,250 --> 00:03:46,830 And that is because you might have guessed it, we implemented a stacked base. 41 00:03:48,130 --> 00:03:49,210 Linked list. 42 00:03:49,840 --> 00:03:55,930 So while we were learning Linked List, we were actually implementing a stack as well. 43 00:03:56,530 --> 00:04:04,120 So that is why we're not going to spend too much time talking about a stack, because while we were 44 00:04:04,120 --> 00:04:08,890 learning linked lists, we also learned what a stack is and how to implement a stack. 45 00:04:09,640 --> 00:04:10,360 But. 46 00:04:11,390 --> 00:04:16,250 A stack does have a counterpart and and its counterpart is a Q. 47 00:04:16,700 --> 00:04:23,720 So in the next lecture we will go over what a Q is and then we will implement our own Q.