40 likes | 116 Views
Step-by-step guide to implement a deque using Java arrays. Learn how to enqueue and dequeue elements, and test with examples.
E N D
Deques enqueueTail(5) enqueueHead(3) 1 4 1 3 1 4 1 3 1 4 1 5 dequeueHead( ) dequeueHead( ) dequeueTail( ) 4 1 1 4 1 1 4 1 5
Example 1:DequeAsArrayStep1: Create a project named DequeAsArrayTest.Step2: Copy and paste the ADTs folder in DequeAsArrayTest folder.Step3: At the beginning of your lab4 Java file import the package ADTs (all the classes).importADTs.DequeAsArray;importADTs.Visitor;importADTs.IntegerPrintingVisitor;Step4: Define a class (DequeAsArrayTest) in which:You create the main() method1. Instantiate the DequeAsArrayclass with object named queue1. 2. Fill queue1with the integers 5, 7, 8, and 3 (use the method enqueue(Object object)).3. Display the elements of queue1: use the showcontent().4. insert 6 as A head (use the method enqueueHead(Object object)).5. insert 9 as A Tail (use the method enqueueTail(Object object)).6. Display the elements of queue1: use the showcontent().7. remove head (use the method dequeueHead()).8. remove Tail (use the method dequeueTail()).9. Display the elements of queue1: use the accept() method of the interface Visitor.System.out.println("Visiting Stack Elements Using Visitor"); Visitor v = new IntegerPrintingVisitor();
Example 2 : Using steps in Example 1 to test DequeAsLinkedList.Your file in ADTS to Be checked is (DequeAsLinkedList).