 Welcome to this course on data structures and algorithms. Today, we shall be discussing implementation of queues using arrays. You will recall that last time we discussed the basic nature of queues. In order to implement queues, we will use an array with fixed size to illustrate the formation of the queue insertion and removal of the elements etcetera. The definition is very simple. We define an array char a with max size as 3 just for the purpose of illustration and we have a variable called n size. We define the queue structure like this. Recall that we need to implement the following functions initialization of the queue, then two functions to check the status empty or full, a function to inspect the front which is similar to top and insertion of an element in the queue. Please note that insertion has to happen logically at the rear of the queue. However, we do not really count rear as we shall see and the main function front which is similar to the pop. This is what will give us the element at the beginning of the queue or front of the queue. So, let us look at these functions. The structure definition which we have already seen just defines the queue. The initialization of queue is very simple. I set the queue size to 0. Now, comes the two status reporting functions whether the queue is empty or whether the queue is full. Again very simple. I just check the size. If it is 0, it is empty. If it is already equal to max size, it is full. Next comes the returning of the front element. So, I want to examine what is the front element. I want to inspect the front element. Assume that queue has only one element f. It will look like this. Size value will be pointing to actually the next element of the array which is first element. The 0th element will contain f which already exists as one element. Clearly, this is the front of the queue as well. Now, if queue is empty, I return false. Else, I put into the element the value of a which is size minus 1. That means this. So, this is how it will return the front of the element to me for inspection. Please note that the inspect front function does not change the status of the queue nor the contents of the queue. We will now look at how an element is inserted in the queue. The function bool queue insert as in the past cases will return a boolean value whether the operation was successful or not. But the element to be inserted is given as this care element. Now, assume for the purpose of this discussion that r and f are already present in the queue as shown here. r and f are already present in the queue. I need to insert a new element y. Notice that y must logically be at the end of the queue and therefore, the element at the front which is assumed to be f shall always remain at the front. Currently, the queue contains only two elements r and f. Now, we as usual examine whether the queue is full. If it is full, we return false, we cannot insert. But otherwise, notice what we do. We push all the existing elements in the queue further up. So, that f which was here, we would like it to come here. r which was here, we would like to come here. And this is what this iteration for int i equal to q size to i, i minus minus will do. That means now, f will come here, r will come here. This is the position where we want to insert the new element that we are given y. So, notice all that we simply do is at 0th position of this array, we insert the new element and increment the size by 1, because the total number of elements has increased by 1. So, it is again a very simple operation. Just remember what we are doing. We are pushing all the existing elements of the queue. So, that f remains at the front and the 0th position which is so vacated now will be used to insert the new element. Very simple. How do we remove the front element from the queue? The queue front operation is actually same as stack pop operation. So, here if the queue is empty, of course, nothing is done. But if queue is not empty, all that I do is I reduce the size of the operational array by 1 by putting size minus minus and the element which is at the front which is pointed to originally by size is now returned as the element. So, very simple operation. Now, the effective size of the array is reduced to only 2 and f has been returned back. We can now write our main program. You will notice a great similarity between this main program and the main program that we wrote to illustrate the implementation of stacks. We define a variable queue one as queue. We define an element care. We initialize the queue. We confirm notionally that it is not empty. Of course, it will not be empty at the beginning. Next we insert one element f. Notice how it is inserted. I put f to element, call this queue insert and print a message saying that it has been inserted properly. Of course, if the array is already full, I will get an error which will not happen in this case. In exactly similar fashion, I can insert two more elements say r and y. After having inserted f, r and y, because I have assumed the maximum size of my array to be 3, there is strictly no place anymore for any new element in the queue. Therefore, if I try to insert one more element x using exactly the same code, this time I will get an error sorry cannot insert because queue is full. Let us look at the ability to access the front element. If queue inspect front is true that means there is indeed an element it will be returned to me in the value of element which I can print. Next we consider removing all elements from the queue. Please note that they must occur in the same order that means all removal will be from the front. This way there is no difference between the stack and queue because all elements are removed from the top in stack and all elements are removed from the front in queue. We already written the function equivalent of pop which is queue front. We will simply execute that function multiple times. Here again I have used an artificial iteration which run 10 times. We know that in this example our maximum size is only 3. So, after getting three elements out of the queue, we will suddenly hit upon an error because queue is empty and I cannot remove any further. Like last time the output of this program will be exactly like this queue is empty as expected at the beginning. Then the elements are inserted one after another. Then I will get an error saying I cannot insert any new element and finally when I examine the front element and subsequently I remove all the elements from the front in that order f r and y. This was a very simple and straightforward implementation. Next session we will discuss the implementation of queues using linked list. Thank you.