và các công trình từ đó bằng cách nhân phạm vi hai từng theo thời gian. Bảng cho thấy làm thế nào điều này sẽ cho những bước đầu tiên. Bảng : Quyền hạn của Hai Để đơn giản, trong chương trình này chúng tôi đã giảm số lượng của các dữ liệu trong mỗi liên kết 2-1. Điều này làm cho nó dễ dàng hơn để hiển thị các nội dung liên kết. | Insert a few more items. The Rear arrow moves upward as you d expect. Notice that once Rear has wrapped around it s now below Front the reverse of the original arrangement. You can call this a broken sequence the items in the queue are in two different sequences in the array. Delete enough items so that the Front arrow also wraps around. Now you re back to the original arrangement with Front below Rear. The items are in a single contiguous sequence. Figure Rear arrow at the end of the array MaxSni I. Figure Rear arrow wraps around Java Code for a Queue The program features a Queue class with insert remove peek isFull isEmpty and size methods. The main program creates a queue of five cells inserts four items removes three items and inserts four more. The sixth insertion invokes the wraparound feature. All the items are then removed and displayed. The output looks like this 40 50 60 70 80 - 107 - Listing shows the program. Listing The Program demonstrates queue to run this program C java QueueApp import . for I O class Queue private int maxSize private int queArray private int front private int rear private int nItems ----------------------------------------------------------------- - public Queue int s constructor maxSize s queArray new int maxSize front 0 rear -1 nItems 0 ----------------------------------------------------------------- - public void insert int j put item at rear of queue if rear maxSize-1 deal with wraparound rear -1 queArray rear j increment rear and insert nItems one more tem ------------------------------------------------------------------ - public int remove take item from front of queue int temp queArray front get value and incr front if front maxSize deal with wraparound front 0 nItems-- one less item return temp ------------------------------------------------------------------ - public int peekFront peek at front of queue - 108 - return queArray front .