‫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
‫we do it, it's going to look something like this, and then we'll add that node into the Q.
‫That's what it will look like when we have items in the Q and then, of course, if we have an empty
‫Q will have first and last point to that new node.
‫So we'll start our function out like this.
‫We'll pass it a value and we'll use that value to create the node like this.
‫And then we'll start out by adding this to an empty Q where we have first and last point to the new
‫node.
‫And in order to do that, we have to test to see is the Q empty?
‫And we'll do that by saying if the length is equal to zero, we'll set first to be equal to new node
‫like this and then we'll set last to be equal to new node like this.
‫So now let's take this code and add it in with the rest of our code.
‫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
‫out this else statement.
‫We'll say last next equals new node.
‫That is last.
‫Next equals new node.
‫And that will set last to be equal to new node, which moves that over and adds that into our queue.
‫So now let's add this code in with the rest of our code.
‫And the only thing left to do is that we need to increase the length by one.
‫So we'll look at this code in a moment in vs code.
‫And when we do, we're going to start out by creating a queue with one item in it with a value of one.
‫And then we'll run in queue and then our queue will have one two.
‫So now let's flip over and take a look at this.
‫So there is our NQ member function there and I'll scroll up.
‫And in our main function, this is the line where we create that new queue with one item with a value
‫of one, and it's with this line that we're going to run in queue and add that second node with a value
‫of two.
‫And with this line we'll print that out and I'll run this.
‫And you can see that our queue has two nodes with a value of one and two and that is our function for
‫in queue.