‫So now we're going to write our function for DK2 and with DK2, we're just going to remove that first
‫node from the queue and we have a couple of edge cases.
‫One for when we have one node in the queue and another edge case for when we have an empty queue.
‫So we'll start our code out like this.
‫And just like we did with the pop function for stacks, we're going to return an integer and then we'll
‫say if the length is equal to zero, return int min.
‫And we talked about int min in the pop function for stacks.
‫So if you don't recognize this or why we're doing this here, that is covered at length in that video.
‫So now let's look at when we have one item in the queue, we'll create a variable temp to point at that
‫node like that, and we will also create a variable to store the value of the node that's going to be
‫D cubed.
‫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
‫is equal to one, we'll set first and last to be equal to null pointer like that.
‫So now let's put this in with the rest of our code.
‫This is for when we have zero items in the queue and this is for when we have one item and for two or
‫more items we'll say else and now we'll build out this else statement.
‫So we'll start out by moving first over one node.
‫We'll set first to be equal to first.
‫Next, we'll do that with this line of code first equals first next, and that moves that over and then
‫we'll delete temp, which removes that node and we'll decrement the length by one and then finally we'll
‫return that dq'd value.
‫So now let's add this in with the rest of our code, and that is the entire DX queue function.
‫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
‫test to make sure it works when we have two or more items in the queue and that it also works when we
‫have one item.
‫And then we'll also run it when the queue is empty and we'll expect to get int min returned.
‫So now let's flip over to VS code and take a look at this.
‫So there is our d Q member function there added to our queue class and I'll scroll up.
‫And in our main function, this creates that queue with a values of two and one, and with these three
‫lines of code will run de queue three different times and I'll run this and you can see up here that
‫we have a decode value of two than a decode value of one.
‫And the third time we ran dd Q The queue is empty and this returns int men and that is our function
‫for dd q.