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
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++
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...
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...
In C++, Implement the queue ADT with a singly linked list
In C++, Implement the queue ADT with a singly linked list
Create a Netbeans project called LineNumbers The program should do the following: –Ask the user for...
Create a Netbeans project called LineNumbers The program should do the following: –Ask the user for how many lines of text they wish to enter –Declare and initialize an array of Strings to hold the user’s input –Use a while loop to prompt for and read the Strings (lines of text) from the user at the command line. Typically, this would be a 'for' loop since we know the number of times to execute the loop based upon the number...
C++ program using Eclipse IDE The C++ program should have concurrency. The C++ program should create...
C++ program using Eclipse IDE The C++ program should have concurrency. The C++ program should create 2 threads that will act as counters. One thread should count down from 5 to 0. Once that thread reaches 0, then a second thread should be used to count up to 20.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT