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.
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...
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.
Using (C programming language) Create a health monitoring program, that will ask user for their name,...
Using (C programming language) Create a health monitoring program, that will ask user for their name, age, gender, weight, height and other health related questions like blood pressure and etc. Based on the provided information, program will tell user BMI, blood pressure numbers if they fall in healthy range or not and etc. Suggestions can be made as what should be calorie intake per day and the amount of exercise based on user input data. User should be able to...
Using the linked list abstract data type “Queue ADT”, write a menu dirven user interfece to...
Using the linked list abstract data type “Queue ADT”, write a menu dirven user interfece to teach each of the operations in the ADT. Any errors discovered during the processing should be printed as a part of the test result. Please Use C++ language.
Write a c++program using queue to find the minimum value in a queue. Use the above...
Write a c++program using queue to find the minimum value in a queue. Use the above program for implementing queue. You must use dequeue function to read values from queue.  
Create a small program that contains the following. ask the user to input their name ask...
Create a small program that contains the following. ask the user to input their name ask the user to input three numbers check if their first number is between their second and third numbers
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT