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 me on this app how do you take a picture of your work
IrinaVladis [17]
You take a picture on your regular camera. Then you go you go to the thingamajigger that looks like a paper clip. You tap it and choose the photo.
6 0
3 years ago
Determine the number of bytes necessary to store an uncompressed RGB color image of size 640 × 480 pixels using 8, 10, 12 and 14
dexar [7]

Answer:

For 8 bits / Color Channel: 921, 600 bytes.

For 10 bits / Color Channel: 1,152,000 bytes.

For 12 bits / Color Channel: 1,382,400 bytes.

For 14 bits / Color Channel : 1,612, 800 bytes.

Explanation:

Un uncompressed RGB color image of 640 pixels wide by 480 pixels height (VGA resolution) uses 3 samples of x bits fin order to represent the quantity of each primary color (red, green and blue) in a given pixel of the image.

So, if we use 8 bits/ sample, we can calculate the bytes needed to store a complete image as follows:

640*480*3*8 bits = 7, 372,800 bits. (1)

As, by definition, 1 byte= 8 bits, we have:

Nº of bytes = 7,372,800 / 8 = 921,600 bytes. (2)

In order to get the bytes needed to store the same image, using 10, 12 and 14 bits/ sample, all we need is replacing 8 by 10, 12 and 14 in (1), and then dividing by 8 as in (2).

Proceeding in this way we obtain:

640*480*3*10 = 9,216,000 bits ⇒    1,152,000 bytes.

640*480*3*12 = 11,059,200 bits ⇒   1,382,400 bytes.

640*480*3*14=   12,902,400 bits ⇒  1,612,800 bytes.

8 0
4 years ago
When installing a Windows 10 an already installed Windows 7 what happen​
astra-53 [7]

Answer:

are u updating it? or u r rooting it?

4 0
3 years ago
Read 2 more answers
Which tool can be used to code basic HTML? Text editor JavaScript CSS HTML
makvit [3.9K]
A text editor can go good when coding HTML.
8 0
3 years ago
Read 2 more answers
Which shortcut key aligns to the center of a page
riadik2000 [5.3K]

Answer:

To make text centered, select and highlight the text first, then hold down Ctrl (the control key) on the keyboard and press E. To make text right aligned, select and highlight the text first, then hold down Ctrl (the control key) on the keyboard and then press R.

Explanation:

4 0
3 years ago
Other questions:
  • Write a program (C++) that reads a number between 1,000 and999,999 from the user where the user enters a comma in the input.Then
    13·1 answer
  • An application server is used to communicate between a Web server and an organization's back-end systems.
    6·1 answer
  • Why operating system is important software for a computer give five reasons
    13·1 answer
  • You have an email that you are sending to a friend. You want to ensure it retains its integrity during transit, so you decide to
    5·1 answer
  • Judy forgot where she saved a certain file on her computer. Therefore, she searches for all files with a .jpg file extension. Wh
    7·2 answers
  • All the network nodes are connected to each other
    8·1 answer
  • You want to substitute one word with another throughout your
    13·1 answer
  • <img src="https://tex.z-dn.net/?f=4%2C000%201%20tenth" id="TexFormula1" title="4,000 1 tenth" alt="4,000 1 tenth" align="absmidd
    7·2 answers
  • The USGS and National Weather Service have many sensors collecting data about natural events.
    8·2 answers
  • Ginny faced an application error while executing the recorder in opera. Which web browser is generally recommended to use with r
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!