TAILIEUCHUNG - Data Structures & Algorithms in Java PHẦN 3

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 .

TAILIEUCHUNG - Chia sẻ tài liệu không giới hạn
Địa chỉ : 444 Hoang Hoa Tham, Hanoi, Viet Nam
Website : tailieuchung.com
Email : tailieuchung20@gmail.com
Tailieuchung.com là thư viện tài liệu trực tuyến, nơi chia sẽ trao đổi hàng triệu tài liệu như luận văn đồ án, sách, giáo trình, đề thi.
Chúng tôi không chịu trách nhiệm liên quan đến các vấn đề bản quyền nội dung tài liệu được thành viên tự nguyện đăng tải lên, nếu phát hiện thấy tài liệu xấu hoặc tài liệu có bản quyền xin hãy email cho chúng tôi.
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.