![]() Otherwise keep increasing the value of rear and insert each element one by one having rear as the index. If the item is to be inserted as the first element in the list, in that case set the value of front and rear to 0 and insert the element at the rear end. however, the queue will look something like following.Īlgorithm to insert any element in a queueĬheck if the queue is already full by comparing rear to max - 1. The value of rear will become 5 while the value of front remains same.Īfter deleting an element, the value of front will increase from -1 to 0. After inserting an element into the queue shown in the above figure, the queue will look something like following. ![]() However, the value of rear increases by one every time an insertion is performed in the queue. Since, No deletion is performed in the queue till now, therefore the value of front remains -1. The above figure shows the queue of characters forming the English word "HELLO". Array representation of a queue containing 5 elements along with the respective values of front and rear, is shown in the following figure. Initially, the value of front and queue is -1 which represents an empty queue. Front and rear variables point to the position from where insertions and deletions are performed in a queue. ![]() front and rear, that are implemented in the case of every queue. We can easily represent queue by using linear arrays. Next → ← prev Array representation of Queue
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |