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
Savatey [412]
4 years ago
14

HW4:

Computers and Technology
1 answer:
julsineya [31]4 years ago
5 0

Answer:

Check the explanation

Explanation:

1)

import java.util.*;

public class ArrayStack {

// Declare an Array List

ArrayList<String> aList;

// Constructor that Instantiates arrayList object

ArrayStack() {

aList = new ArrayList<String>();

}

public void push(String object) {

//Add the Value

aList.add(object);

}

public String pop() {

String ret = null;

//Check the size of list if 0 means Stack is Empty

if (aList.isEmpty())

System.out.println("Stack is Empty");

else {

//Return the last value entered as Stack is LAST IN FIRST OUT

// Remove it

ret = aList.get(aList.size() - 1);

aList.remove(aList.size() - 1);

}

return ret;

}

public String peek() {

String ret = null;

//Check the size of list if 0 means Stack is Empty

if (aList.isEmpty())

System.out.println("Stack is Empty");

else {

//Return the last value entered as Stack is LAST IN FIRST OUT

// DO not remove it

ret = aList.get(aList.size() - 1);

}

return ret;

}

public boolean isEmpty() {

//Check the size of list if 0 means Stack is Empty

return aList.size()==0;

}

public static void insertionSort(int arr[], int n)

{

int i, j;

for(i=2;i< n;i++){

arr[0] = arr[i];

j = 1;

while(j <= i-1){

/* implement your code here /*

/* you must start compare arr[j] with a[0], notice that j = 1 */

}

}

}

public static void main(String[] args) {

// TODO Auto-generated method stub

ArrayStack aStack = new ArrayStack();

aStack.push("Hey");

aStack.push("Hello");

aStack.push("Bye");

System.out.println(aStack.pop());

System.out.println("Peek: " + aStack.peek());

System.out.println(aStack.pop());

System.out.println(aStack.isEmpty());

System.out.println(aStack.pop());

// int arr[] = new int[] {3,4,2,1,6,7,5};

// insertionSort(arr,7);

// System.out.println(Arrays.toString(arr));

}

}

LinkedQueue

interface QueueInterface {

public void enqueue(Object item);

// Effect: Adds item to the rear of this queue.

// Precondition: This queue is not full.

// Postcondition: item is at the rear of this queue.

public Object dequeue();

// Effect: Removes front element from this queue and returns it.

// Precondition: This queue is not empty.

// Postconditions: Front element has been removed from this queue.

// Return value = (the removed element)

public boolean isEmpty();

// Effect: Determines whether this queue is empty.

// Postcondition: Return value = (this queue is empty)

public boolean isFull();

// Effect: Determines whether this queue is full.

// Postcondition: Return value = (queue is full)

public int size();

}

public class LinkedQueue implements QueueInterface {

private class QueueNode

// Used to hold references to queue nodes for the linked queue

// implementation

{

private Object info;

private QueueNode link;

}

private QueueNode front; // reference to the front of this queue

private QueueNode rear; // reference to the rear of this queue

public LinkedQueue()

// Constructor

{

front = null;

rear = null;

}

public void enqueue(Object item)

// Adds item to the rear of this queue.

{

QueueNode newNode = new QueueNode();

newNode.info = item;

newNode.link = null;

if (rear == null)

front = newNode;

else

rear.link = newNode;

rear = newNode;

}

public Object dequeue()

// Removes front element from this queue and returns it.

{

Object item;

item = front.info;

front = front.link;

if (front == null)

rear = null;

return item;

}

public boolean isEmpty()

// Determines whether this queue is empty.

{

if (front == null)

return true;

else

return false;

}

public Object peek()

// Determines whether this queue is empty.

{

if (front == null)

return null;

else

return front.info;

}

public int size()

// Determines whether this queue is empty

{

QueueNode curr = front;

int count = 0;

while (curr != null) {

++count;

curr = curr.link;

}

return count;

}

public String toString()

// Determines whether this queue is empty.

{

QueueNode curr = front;

String res = "";

while (curr != null) {

res = res + curr.info + " ";

curr = curr.link;

Note that i could not complete the answers to all the question because the codes are above the brainly character limit, you might need to ask the question 2 and 3 separately.

Kindly check the outputs in the attached images below

You might be interested in
PLEASE HELP FAST!!!!!!Color photographs often look better on which type of photo paper
balandron [24]
Im pretty sure its either matte or glossy. Im not sure though
4 0
3 years ago
Given main() and a base Book class, define a derived class called Encyclopedia. Within the derived Encyclopedia class, define a
NemiM [27]

Answer:    

Here is the Encyclopedia class:

public class Encyclopedia extends Book {   //class  Encyclopedia that inherits from class Book

  private String edition; //declare private member variable edition of type String  

  private int numVolumes;      //declare private member variable numVolumes of type int

  public void setEdition(String ed) {  //mutator method of class that sets the value of edition

     edition = ed;    }     //assigns the value of ed to edition member field

  public void setNumVolumes(int numVol) { //mutator method of class that sets the value of numVol

     numVolumes = numVol;    }  //assigns the value of numVolumes to edition member field

  public String getEdition() {  //accessor method to get the value of edition

     return edition;    }     //returns the current value of edition

  public int getNumVolumes() {  //accessor method to get the value of numVolumes

     return numVolumes;    }       //returns the current value of numVolumes

  public void printInfo() {  //method to print edition and number of volumes information on output screen

     super.printInfo();  // The super keyword refers to parent class Book objects. It is used to call Book method and to eliminate the confusion between Book class printInfo method and Encyclopedia printInfo  method

     System.out.println("   Edition: " + edition);  //prints edition info

     System.out.println("   Number of Volumes: " + numVolumes);    }  }  //prints number of volumes info

Explanation:

The explanation is provided in the attached document.

7 0
4 years ago
What is working with others to find a mutually agreeable outcome?
aleksley [76]
Verbal communication im pretty sure
6 0
3 years ago
Read 2 more answers
Which IDEs support multiple high-level programming languages? Select all that apply.
rewona [7]

Answer:

The correct answer to this question is given below in the explanation section.

Explanation:

This question is about integrated development environments (IDEs) that support multiple high-level programming languages.

All mentioned IDEs such as Eclipse, Visual Studio, and Xcode support multiple high-level programming languages except Linux.

Using Eclipse, you can do Java programming easily and can build Java-based programs, and also you can do android programming in Eclipse while importing required android settings and libraries. Visual Studio is a Microsoft IDE, in which you can build desktop, web, and mobile, and windows phone app easily using high-level programming. Xcode is an integrated development environment for macOS containing a suite of software development tools developed by Apple for developing software for macOS, iPadOS, iOS, watchOS, and tvOS.

While Linux is not an IDEs, it is an open-source operating system based on Linux kernel.

8 0
3 years ago
What letters identify moisture-resistant latex rubber insulation? A. RUH B. RUW C. RHH D. RH
natita [175]

The answer is C. RHH

4 0
3 years ago
Other questions:
  • In a digital drawing program, when an object is highlighted, boxes appear at the sides and corners. These boxes can be grabbed a
    13·1 answer
  • A 10MB file is compressed into a 2MB file for storage. What is the compression ratio?
    6·1 answer
  • In microsoft what displays when the mouse pointer rests on selected text or data that can be formatted.
    8·1 answer
  • 18. Which type of briefing is delivered to individual resources or crews who are assigned to operational tasks and/or work at or
    14·1 answer
  • A web ______ is a computer that delivers requested webpages to your computer or mobile device.
    7·1 answer
  • What the best option if you cant show your PowerPoint presentation at all
    6·2 answers
  • As a project manager, why is analysis an important aspect of the job?
    10·1 answer
  • Consider a short, 90-meter link, over which a sender can transmit at a rate of 420 bits/sec in both directions. Suppose that pac
    9·1 answer
  • The success of Eye of the storm exemplifies
    9·1 answer
  • If you are connected to a network that uses DHCP, and you need to terminate your Windows workstation's DHCP lease, which command
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!