


As queue is full, elements will not be inserted. A stack is a limited access data structure - elements can be added and removed from the stack only at the top. Lets’s see how can we implement these in Java. A typical illustration of random access is a book. In this article, you will be introduced to stacks and queues. Similarly, we can implement all of these to the Queue Data Structure too. An array is a random access data structure, where each element can be accessed directly and in constant time. As a wrap around arrangement, if front index is more than array's max index, it is set to 0. Stacks and queues are linear data structures that follow a particular order to add or remove entities. In a queue, addition of a new element and deletion of an element occurs at different end which implies that the element which is added first in the queue will be the first to be removed from the queue. Whenever an element is to be removed from queue, queue get the element using front index and increments the front index. The queue data structure is also available in the Java collection framework as an interface and a few concrete implementations like ArrayBlockingQueue. This method is also termed as enqueue operation. An array can hold a fixed number of containers to store data and operations could be performed on that data. Such an arrangement is called wrap around and such queue is circular queue. A basic data structure that one uses in a day to day programming is an array. If rear end reaches to the last index and it is wrapped to the bottom location. Whenever an element is inserted into queue, queue increments the rear index for later use and stores that element at the rear end of the storage. We define a queue to be a list in which all additions to the list are made at one end, and all deletions from the list are made at the other end. Peek − get the element at front of the queue. A queue is a linear data structure that is open at both ends and the operations are performed in First In First Out (FIFO) order. There is few more operations supported by queue which are following. We're going to implement Queue using array in this article. Remove / dequeue − remove an item from the front of the queue. Data Structure in java is defined as the collection of data pieces that offers an effective means of storing and organising data in a computer. Insert / enqueue − add an item to the rear of the queue.

Queue is kind of data structure similar to stack with primary difference that the first item inserted is the first item to be removed (FIFO - First In First Out) where stack is based on LIFO, Last In First Out principal.
