1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
erica [24]
3 years ago
15

Create an instance of your queue that accepts java.lang.String Objects. Starting with an empty queue, use the enqueue(E e) metho

d to add 10,000 java.lang.String objects
Computers and Technology
1 answer:
Aleksandr-060686 [28]3 years ago
6 0

Answer:

Code is given below:

Explanation:

ode.java:

public class Node

{

String data;

Node next;

Node prev;

public Node(String data,Node next, Node prev){

this.next=next;

this.data=data;

this.prev=prev;

}

public Node(){

}

public String getData(){

return data;

}

public void setData(String data){

this.data=data;

}

public Node getNext(){

return next;

}

public void setNext(Node next){

this.next=next;

}

public Node getPrev(){

return prev;

}

public void setPrev(Node prev){

this.prev=prev;

}

}

Linked Queue.java:

public class LinkedQueues {

    Node head ;

   Node tail;

int size=0;

public Oueues(){

   this.head=null;

   this.tail=null;

}

public boolean isEmpty()

{

   return head == tail;

}    

 public int getSize()

    {

          return size;

  }    

 public void insert(String data){

   Node tmp = new Node(data,null,null);

    tmp.data=data;

    tmp.next=null;

    if(head==null){

        head=tail=tmp;

        head.prev=null;

    }

    else{

        tail.next=tmp;

        tmp.prev=tail;

        tail=tmp;

 }    

 }

 public String remove(){

  if(head.next==tail)

      return null;// list empty

  Node tmp=head.next;

  head.next=tmp.next;

  tmp.next.prev=head;

  list();

  return tmp.data;

 }

 public void list(){

     System.out.println("Queues");

     if(size==0){

         System.out.println("İs Empty");

     }

    Node tmp=head;

    while(tmp !=tail.getNext()){

        System.out.println(tmp.getVeri()+" ");

      tmp= tmp.getNext();

    }

     System.out.println();

 }

Linkedstack.java:

public class LinkedStack {

Node head = null;

Node tail = null;

int size=0;

     public int getSize() {

    return size;

      }

  public boolean isEmpty()

      {

   return head == null;

   }    

 public void Push(String data) {

    tail = head;

   head = new Node(data,null,null);

   head.data=data;

   head.next= tail;

   head.prev = null;

   if(tail != null) {

       tail.prev=head;

   }

   size++;

 }

 public void Pop() {

   if (!isEmpty()) {

       head = head.next;   // delete first node

       size--;

   } else {

       System.out.println("İs Empty");

   }

}

  public void Top() {

   Node tmp = head;

   while (tmp != null) {

       System.out.println(tmp.getData());

       tmp = tmp.getNext();

   }

}

 }

ArrayBasedQueue.java

import java.util.LinkedList;

import java.util.Queue;

 

public class ArrayBasedQueue

{

 public static void main(String[] args)

 {

   Queue<Integer> q = new LinkedList<>();

 

   // Adds elements {0, 1, 2, 3, 4} to queue

   for (int i=0; i<5; i++)

    q.add(i);

 

   // Display contents of the queue.

   System.out.println("Elements of queue-"+q);

   int removedele = q.remove();

   System.out.println("removed element-" + removedele);

 

   System.out.println(q);

   int head = q.peek();

   System.out.println("head of queue-" + head);

 

   int size = q.size();

   System.out.println("Size of queue-" + size);

 }

}

ArrayBasedStack.java:

import java.io.*;

import java.util.*;

 

public class ArrayBasedStack

{

static void stack_push(Stack<Integer> stack)

{

for(int i = 0; i < 5; i++)

{

stack.push(i);

}

}

 

// Popping element from the top of the stack

static void stack_pop(Stack<Integer> stack)

{

System.out.println("Pop :");

 

for(int i = 0; i < 5; i++)

{

Integer y = (Integer) stack.pop();

System.out.println(y);

}

}

 }

TestTimes.java:

public class TestTimes implements TestTimesInterface

{

 public static enum TimeUnits {};

 public static enum MemoryUnits{};

}

Driver.java:

public class driver

{

public static void main(String args[])

{

   Scanner s = new Scanner(System.in);

   LinkedStack y = new LinkedStack();

   LinkedQueues k = new LinkedQueues();

   ArrayBasedStack as=new ArrayBasedStack();

     ArrayBasedQueue as=new ArrayBasedQueue();

   FileWriter fwy;

   FileWriter fwk;

   File stack = new File("stack.txt");

   if (!stack.exists()) {

       stack.createNewFile();

   } else {

       System.out.println("already exists ");

   }

   BufferedReader reader = null;

   reader = new BufferedReader(new FileReader(stack));

   String line = reader.readLine();

   while (line != null) {

       y.Push(line = reader.readLine());

       System.out.println(line);

   }

   File queue = new File("queue.txt");

   if (!queue.exists()) {

       queue.createNewFile();

   } else {

       System.out.println("already exists ");

   }

   BufferedReader read = null;

   read = new BufferedReader(new FileReader(queue));

   String lines = read.readLine();

   while (lines != null) {

       lines = read.readLine();

       k.insert(lines);

       System.out.println(lines);

   }

int choice;

     System.out.println("1. Stack out- queue add");

     System.out.println("2. Stack add- queue out");

     System.out.println("3. Stack and queue ");

     System.out.println("4. File writer");

     choice = s.nextInt();

   switch (choice) {

       case 1:

           k.insert(s.next());

           k.list();

           y.pop();

           break;

       case 2:

         y.Push(s.next());

           y.Top();

         k.remove();

           break;

       case 3:

           y.Top();

           k.list();

           break;

       case 4:

           fwy = new FileWriter(stack);

           Node no = y.head;

           while (no.next != null) {

               fwy.write("\n" + no.data);

               no = no.next;

           }

           fwy.flush();

           fwy.close();

           fwk = new FileWriter(queue);

           Node noo = k.head;

           while (noo.next != null) {

               fwk.write("\n" + noo.data);

               noo = noo.next;

           }

           fwk.flush();

           fwk.close();

           break;

        }

 

}

}

You might be interested in
MLB The Show 17, which simulates professional baseball games, and Madden Football, which simulates professional football games,
insens350 [35]

Answer:

Sports game

Explanation:

5 0
3 years ago
Unlike memory, this type of storage holds data and programs even after electrical power to the computer system has been turned o
Scrat [10]

Answer:

Secondary memory.

Explanation:

Unlike main memory which loses its content when electrical power to the system is turned off, secondary memory is volatile and persistent in nature. i.e it retains its content whether or not power is supplied to the computer that is holding it. As a matter of fact, they (secondary memory) are meant to store data permanently. Examples of such memory are the hard drives, floppy disks, flash drives, CDs and CDROMs.

Also, unlike the primary or main memory that can be accessed directly by the processor of the computer housing it, secondary memory are not accessed directly.

8 0
2 years ago
What is the difference of expository and reflexive documentary
spayn [35]
The reflexive documentary mode focuses on the relationship between the filmmaker and the audience. While expository documentaries set up a specific point of view or argument about a subject and a narrator often speaks directly to the viewer.
3 0
2 years ago
Using e-mail has decreased the number of hand-written letters that people send to their friends and relatives. this is a ____ fu
k0ka [10]
Hello <span>Alexkalhor5415

</span>Answer: Using e-mail has made it easy, fast, and inexpensive for family members who live in different parts of the united states to keep in touch. this is a positive  function of e-mail.
Hope this helps-Chris
6 0
2 years ago
Attackers need a certain amount of information before launching their attack. One common place to find information is to go thro
VARVARA [1.3K]

Answer:

The answer is Letter D. Dumpster diving.

Explanation:

This process of going through a target's trash is known in the community as dumpster diving. This attack is a technique used to retrieve information that could be used to carry out an attack on a computer network.

It is important to inform that the dumpster diving it is not limited to searching through  the trash for obvious treasures like acess codes or passwords written down on sticky notes.

8 0
2 years ago
Other questions:
  • design aDesign a queue abstract data type for float elements in a language that you know, including operations for enqueue, dequ
    10·1 answer
  • What is gender bias?
    9·1 answer
  • If you wish to maintain a consistent style to all the documents you create, it would be helpful to use a _​
    5·1 answer
  • What does mean I can’t turn on my computer and my computer won’t charge at all
    15·1 answer
  • What are the classifications of computer
    9·1 answer
  • What is the role of science and technology in achieving human’s ultimate goal or the good life?
    8·2 answers
  • How does the autosum command calculate data? Need help ASAP​
    5·1 answer
  • What are the two biggest strength as a student
    7·2 answers
  • Which type of network consists of multiple Windows computers that share information, but no computer on the network serves as an
    15·1 answer
  • You have been asked to replace a cracked screen on a laptop. The replacement screen was delivered today, but it did not include
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!