﻿1
00:00:00,470 --> 00:00:09,260
‫So now we're going to write our function for in Q and in Q is when we add items to the Q, except when

2
00:00:09,260 --> 00:00:15,920
‫we do it, it's going to look something like this, and then we'll add that node into the Q.

3
00:00:16,160 --> 00:00:21,830
‫That's what it will look like when we have items in the Q and then, of course, if we have an empty

4
00:00:21,830 --> 00:00:26,660
‫Q will have first and last point to that new node.

5
00:00:26,960 --> 00:00:29,810
‫So we'll start our function out like this.

6
00:00:29,810 --> 00:00:37,190
‫We'll pass it a value and we'll use that value to create the node like this.

7
00:00:37,550 --> 00:00:43,400
‫And then we'll start out by adding this to an empty Q where we have first and last point to the new

8
00:00:43,400 --> 00:00:44,030
‫node.

9
00:00:44,210 --> 00:00:49,400
‫And in order to do that, we have to test to see is the Q empty?

10
00:00:49,400 --> 00:00:56,150
‫And we'll do that by saying if the length is equal to zero, we'll set first to be equal to new node

11
00:00:56,150 --> 00:01:02,870
‫like this and then we'll set last to be equal to new node like this.

12
00:01:03,290 --> 00:01:07,190
‫So now let's take this code and add it in with the rest of our code.

13
00:01:07,490 --> 00:01:14,390
‫So now let's write the code for when we do have items in our Q, we'll say else and then we'll build

14
00:01:14,390 --> 00:01:16,490
‫out this else statement.

15
00:01:17,220 --> 00:01:20,730
‫We'll say last next equals new node.

16
00:01:20,730 --> 00:01:22,290
‫That is last.

17
00:01:22,740 --> 00:01:25,920
‫Next equals new node.

18
00:01:26,920 --> 00:01:33,790
‫And that will set last to be equal to new node, which moves that over and adds that into our queue.

19
00:01:34,150 --> 00:01:37,780
‫So now let's add this code in with the rest of our code.

20
00:01:38,110 --> 00:01:43,210
‫And the only thing left to do is that we need to increase the length by one.

21
00:01:43,630 --> 00:01:46,720
‫So we'll look at this code in a moment in vs code.

22
00:01:46,720 --> 00:01:53,890
‫And when we do, we're going to start out by creating a queue with one item in it with a value of one.

23
00:01:54,160 --> 00:01:59,350
‫And then we'll run in queue and then our queue will have one two.

24
00:01:59,650 --> 00:02:02,860
‫So now let's flip over and take a look at this.

25
00:02:03,490 --> 00:02:09,010
‫So there is our NQ member function there and I'll scroll up.

26
00:02:09,310 --> 00:02:15,610
‫And in our main function, this is the line where we create that new queue with one item with a value

27
00:02:15,610 --> 00:02:22,780
‫of one, and it's with this line that we're going to run in queue and add that second node with a value

28
00:02:22,780 --> 00:02:23,560
‫of two.

29
00:02:23,830 --> 00:02:27,880
‫And with this line we'll print that out and I'll run this.

30
00:02:28,570 --> 00:02:37,510
‫And you can see that our queue has two nodes with a value of one and two and that is our function for

31
00:02:37,510 --> 00:02:38,440
‫in queue.

