Queue does allow duplicate elements, because the primary characteristic of queue is maintaining elements by their insertion order. And the LinkedList class is a well-known implementation.Some implementations accept null elements, some do not. The following picture illustrates this kind of queue: The Deque interface abstracts this kind of queue, and it is a sub interface of the Queue interface. A deque has two heads, allowing elements to be added or removed from both ends. The Queue interface abstracts this kind of queue.Another kind of queue is double ended queue, or deque. The following picture illustrates a typical queue: Elements in the queue are maintained by their insertion order. New elements are added to the tail, and to-be-processed elements are picked from the head. Characteristics of Queue Basically, a queue has a head and a tail. processed elements are removed from the queue, and new elements are added to the queue.In the Java Collections Framework, Queueis the main interface, and there are four sub interfaces: Deque, BlockingDeque, BlockingQueue, and TransferQueue.Except the Deque interface which is in the java.util package, all others are organized in the package, which is designed for multi-threading or concurrent programming. This processing is called First In First Out or FIFO.During the processing, the queue can be dynamically changed, i.e. Other customers come later are added to the end of the queue. When serving a customer is done, he or she lefts the counter (removed from the queue), and the next customer is picked to be served next. The first customer comes is served first, and after him is the 2 nd, the 3 rd, and so on. Each customer is served one after another, follow the order they appear or registered. Let’s consider a queue holds a list of waiting customers in a bank’s counter. Queue means ‘waiting line’, which is very similar to queues in real life: a queue of people standing in an airport’s check-in gate a queue of cars waiting for green light in a road in the city a queue of customers waiting to be served in a bank’s counter, etc.In programming, queue is a data structure that holds elements prior to processing, similar to queues in real-life scenarios.
0 Comments
Leave a Reply. |