﻿1
00:00:00,420 --> 00:00:07,590
‫So now we're going to build our constructor for our queue, except our queue is going to look like this.

2
00:00:07,920 --> 00:00:11,130
‫So we have to start out by building a node.

3
00:00:11,430 --> 00:00:18,240
‫And just like we saw with link lists and with our stack, we said that this node is very similar to

4
00:00:18,240 --> 00:00:27,390
‫an unordered map with value and next and that we have a constructor that we pass a value and then we

5
00:00:27,390 --> 00:00:35,550
‫say this value equals value, and then we set that next pointer to null pointer and that is our node

6
00:00:35,550 --> 00:00:36,270
‫class.

7
00:00:36,270 --> 00:00:40,260
‫And this is exactly the same as it was in our linked list.

8
00:00:40,770 --> 00:00:45,960
‫So now we'll start building our queue class and we'll create our member variables.

9
00:00:45,960 --> 00:00:54,930
‫Those will be private, so we'll create pointers to the first and last node like this, and then we'll

10
00:00:54,930 --> 00:00:57,240
‫also keep track of the length.

11
00:00:57,480 --> 00:01:02,850
‫So now let's build the constructor, which will be public, and we'll start that constructor out like

12
00:01:02,850 --> 00:01:03,740
‫this.

13
00:01:03,750 --> 00:01:07,320
‫And now let's focus in on just the constructor.

14
00:01:07,560 --> 00:01:09,740
‫So we're passing the queue of value.

15
00:01:09,750 --> 00:01:18,120
‫We'll use that to create the first node in the queue like this, and then we'll set first and last to

16
00:01:18,120 --> 00:01:25,050
‫be equal to new node like this, and then we'll set the length to be equal to one.

17
00:01:25,650 --> 00:01:28,350
‫So this bring back the rest of our code like this.

18
00:01:28,350 --> 00:01:31,770
‫This is our entire queue class so far.

19
00:01:32,070 --> 00:01:35,490
‫And let's focus back in on just the constructor.

20
00:01:35,850 --> 00:01:41,610
‫We would create a new queue and run this constructor by doing something like this.

21
00:01:41,610 --> 00:01:46,200
‫We'll have a queue called my queue and we'll set it equal to new queue.

22
00:01:46,230 --> 00:01:52,500
‫We'll pass it the number seven, and when we run this line of code it will build all of this.

23
00:01:52,680 --> 00:01:55,860
‫It will create that first node with a value of seven.

24
00:01:55,860 --> 00:02:01,950
‫First and last will point to that node, and that will set the length to be equal to one.

25
00:02:02,280 --> 00:02:06,600
‫So now let's flip over to VS Code and take a look at this.

26
00:02:07,240 --> 00:02:10,320
‫So there is our node class there.

27
00:02:10,330 --> 00:02:12,130
‫I'm going to scroll up a little bit.

28
00:02:12,910 --> 00:02:16,450
‫And this here is the code that we just went through.

29
00:02:16,450 --> 00:02:18,550
‫And then I'm going to scroll up again.

30
00:02:18,910 --> 00:02:24,610
‫And then I also created print queue, get first, get last and get length.

31
00:02:24,700 --> 00:02:28,990
‫And then I'll scroll up again here and we'll look at our main function.

32
00:02:29,290 --> 00:02:36,070
‫So that creates that queue that we just saw with one node with a value of seven and then we'll run,

33
00:02:36,070 --> 00:02:41,890
‫get first, get last, get length and finally we'll run print queue.

34
00:02:42,130 --> 00:02:48,160
‫So I'll run this and you can see that first and last point to a node with a value of seven.

35
00:02:48,160 --> 00:02:55,150
‫The length is one and this is what we get from running print queue and it's showing just that one node

36
00:02:55,150 --> 00:02:57,340
‫with a value of seven.

37
00:02:57,790 --> 00:03:02,680
‫So it looks like we have a working queue constructor.

