June 2017
Beginner
1296 pages
69h 23m
English
... interface. Using composition enables us to hide class List<E>’s other public methods from Queue<E>’s client code. Each Queue<E> method delegates to a List<E> method—enqueue calls List<E> method insertAtBack (Fig. 21.11, line 14), dequeue calls List<E> method removeFromFront (line 18), isEmpty calls List<E> method isEmpty (line 22) and print calls List<E> method print (line 25). For reuse, class Queue<E> is declared in package com.deitel.datastructures. Again, we do not import List<E> because it’s in the same package.
1 // Fig. 21.11: Queue.java
2 // Queue uses class List.
3 package com.deitel.datastructures;
4
5 import java.util.NoSuchElementException;
6
7 public class Queue<E> {
8 private List<E> queueList;
9
10 // constructor
11 public ...Read now
Unlock full access