Question

In: Computer Science

Using the Queue ADT: Create a program that uses a Queue. Your program should ask the...

Using the Queue ADT:

Create a program that uses a Queue. Your program should ask the user to input a few lines of text and then outputs strings in same order of entry. (use of the library ArrayDeque)

In Java please.

Solutions

Expert Solution

ANSWER:--

GIVEN THAT:--

CODE:

// import ArrayDequeue
import java.util.*;

// extends abstract queue
public class Queue extends adtqueue {
  
   Deque<Character> deque = new ArrayDeque<Character>(10);

   public static void main(String[] args) {

//       making instance of Queue
       Queue q= new Queue();
      
//      
System.out.println();
      
       System.out.println("Operation on String : WASHINGTON");
      
       System.out.println();
      
       String test="WASHINGTON";
      
       System.out.print("String entered into Queue : WASHINGTON");
       q.enqueue('W');
       q.enqueue('A');
       q.enqueue('S');
       q.enqueue('H');
       q.enqueue('I');
       q.enqueue('N');
       q.enqueue('G');
       q.enqueue('T');
       q.enqueue('O');
       q.enqueue('N');
      
       System.out.println();
       System.out.println();
      
       System.out.print("String Dequeueed from Queue by one by one chars : ");
      
       while(!q.isEmpty()) {
          
           System.out.print(q.dequeue()+" ");
          
       }
      
       System.out.println();
       System.out.println();
      
       System.out.println("Yes! String is in Same order");
          
   }
  
//   return is Empty
   boolean isEmpty() {
      
       return deque.isEmpty();
      
   }
  

   @Override
   void enqueue(char i) {
      
       deque.add(i);
      
   }

   @Override
   char dequeue() {
      
       char c=deque.remove();
      
       return c;
   }

   @Override
   char top() {
      
       char c=deque.peekFirst();
      
       return 0;
   }
  
  
}


// Abstract Queue class

abstract class adtqueue{

   abstract void enqueue(char i);
  
   abstract char dequeue();
  
   abstract char top();
  
}

SAMPLE OUTPUT:


Related Solutions

Using the Stack ADT: Create a program that uses a stack. Your program should ask the...
Using the Stack ADT: Create a program that uses a stack. Your program should ask the user to input a few lines of text and then outputs strings in reverse order of entry. (Optional) Create a similar program that uses a stack. Your new program should ask the user to input a line of text and then it should print out the line of text in reverse. To do this your application should use a stack of Character. In Java...
2. Using the Stack ADT: Create a program that uses a stack. Your program should ask...
2. Using the Stack ADT: Create a program that uses a stack. Your program should ask the user to input a few lines of text and then outputs strings in reverse order of entry. In Java please.
JAVA: Implement a Queue ADT using a circular array with 5 string elements. Create a Queue...
JAVA: Implement a Queue ADT using a circular array with 5 string elements. Create a Queue object and try various operations below. Queue myQueue = new Queue(); myQueue.enqueue(“CPS 123”); myQueue.enqueue(“CPS 223”); myQueue.enqueue(“CPS 323”); myQueue.dequeue(); myQueue.enqueue(“CPS 113”); myQueue.enqueue(“CPS 153”); string course = myQueue.front(); // course should be CPS 223 size = myQueue.size(); // size should be 4 // output course and size
Given a queue of integers, write an algorithm in Pseudocode that, using only the queue ADT,...
Given a queue of integers, write an algorithm in Pseudocode that, using only the queue ADT, calculates and prints the sum and the average of the integers in the queue without changing the contents of the queue.
Create an ADT class that creates a friend contact list. The program should be able to...
Create an ADT class that creates a friend contact list. The program should be able to add, remove and view the contacts. In C++
Give a complete implementation of the queue ADT using a singly linked list that includes a...
Give a complete implementation of the queue ADT using a singly linked list that includes a header sentinel (in Python).
PYTHON- create a queue class that uses a LINKEDLIST in order to store data. this queue...
PYTHON- create a queue class that uses a LINKEDLIST in order to store data. this queue will call on a linkedlist class class Queue: def __init__(self): self.items = LinkedList() #has to be O(1) def enqueue(self, item): #has to be O(1) def dequeue(self): def is_empty(self): def __len__(self):
Using a single queue (linkedQueue), re-implement the concept of Stack ADT, what is the complexity of...
Using a single queue (linkedQueue), re-implement the concept of Stack ADT, what is the complexity of the method push, pop, top, isEmpty, and size. You should not use any extra data structure. Related codes: public interface Stack<E> { int size( ); boolean isEmpty( ); void push(E e); E top( ); E pop( ); } public class LinkedStack<E> implements Stack<E> { private SinglyLinkedList<E> list = new SinglyLinkedList<>( );    public LinkedStack( ) { }    public int size( ) { return...
Write C++ programs to implement Queue ADT data structure using Linked List.
Write C++ programs to implement Queue ADT data structure using Linked List.
Create a dynamic array-based Queue ADT class in C++ that contains enqueue(Inserts newElement at the back...
Create a dynamic array-based Queue ADT class in C++ that contains enqueue(Inserts newElement at the back ) and dequeue(Removes the frontmost element ). If the size of the array is equal to the capacity a new array of twice the capacity must be made. The interface is shown: class Queue { private: int* elements; unsigned elementCount; // number of elements in the queue unsigned capacity; // number of cells in the array unsigned frontindex; // index the topmost element unsigned...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT