﻿1
00:00:00,480 --> 00:00:07,380
‫So now we're going to write our function for DK2 and with DK2, we're just going to remove that first

2
00:00:07,380 --> 00:00:11,490
‫node from the queue and we have a couple of edge cases.

3
00:00:11,490 --> 00:00:17,910
‫One for when we have one node in the queue and another edge case for when we have an empty queue.

4
00:00:18,330 --> 00:00:20,490
‫So we'll start our code out like this.

5
00:00:20,490 --> 00:00:26,940
‫And just like we did with the pop function for stacks, we're going to return an integer and then we'll

6
00:00:26,940 --> 00:00:31,830
‫say if the length is equal to zero, return int min.

7
00:00:32,130 --> 00:00:36,060
‫And we talked about int min in the pop function for stacks.

8
00:00:36,060 --> 00:00:42,750
‫So if you don't recognize this or why we're doing this here, that is covered at length in that video.

9
00:00:43,140 --> 00:00:49,830
‫So now let's look at when we have one item in the queue, we'll create a variable temp to point at that

10
00:00:49,830 --> 00:00:56,910
‫node like that, and we will also create a variable to store the value of the node that's going to be

11
00:00:56,910 --> 00:00:57,750
‫D cubed.

12
00:00:57,750 --> 00:01:04,860
‫We'll call that dq'd value and we'll set it to be equal to first value and then we'll say if the length

13
00:01:04,860 --> 00:01:11,430
‫is equal to one, we'll set first and last to be equal to null pointer like that.

14
00:01:11,940 --> 00:01:14,880
‫So now let's put this in with the rest of our code.

15
00:01:14,910 --> 00:01:22,200
‫This is for when we have zero items in the queue and this is for when we have one item and for two or

16
00:01:22,200 --> 00:01:27,300
‫more items we'll say else and now we'll build out this else statement.

17
00:01:27,600 --> 00:01:30,750
‫So we'll start out by moving first over one node.

18
00:01:30,750 --> 00:01:33,420
‫We'll set first to be equal to first.

19
00:01:33,450 --> 00:01:41,100
‫Next, we'll do that with this line of code first equals first next, and that moves that over and then

20
00:01:41,100 --> 00:01:49,290
‫we'll delete temp, which removes that node and we'll decrement the length by one and then finally we'll

21
00:01:49,290 --> 00:01:52,050
‫return that dq'd value.

22
00:01:52,530 --> 00:01:58,410
‫So now let's add this in with the rest of our code, and that is the entire DX queue function.

23
00:01:58,620 --> 00:02:05,460
‫We'll look at this in a moment in V's code and when we do we'll create this queue because we want to

24
00:02:05,460 --> 00:02:11,130
‫test to make sure it works when we have two or more items in the queue and that it also works when we

25
00:02:11,130 --> 00:02:12,510
‫have one item.

26
00:02:12,510 --> 00:02:18,570
‫And then we'll also run it when the queue is empty and we'll expect to get int min returned.

27
00:02:18,960 --> 00:02:22,620
‫So now let's flip over to VS code and take a look at this.

28
00:02:23,340 --> 00:02:30,630
‫So there is our d Q member function there added to our queue class and I'll scroll up.

29
00:02:30,960 --> 00:02:37,890
‫And in our main function, this creates that queue with a values of two and one, and with these three

30
00:02:37,890 --> 00:02:45,390
‫lines of code will run de queue three different times and I'll run this and you can see up here that

31
00:02:45,390 --> 00:02:50,160
‫we have a decode value of two than a decode value of one.

32
00:02:50,160 --> 00:02:58,380
‫And the third time we ran dd Q The queue is empty and this returns int men and that is our function

33
00:02:58,560 --> 00:02:59,970
‫for dd q.

