Java Data Structure Doubly Linked List
/*
* Complete the swap(int index) method
* No other methods/variables should be added/modified
*/
public class A3DoubleLL<E> {
/*
* Grading:
* Swapped nodes without modifying values - 2pt
* Works for all special cases - 1pt
*/
public void swap(int index) {
//swap the nodes at index and
index+1
//change the next/prev connections,
do not modify the values
//do not use
delete/remove/insert/add to help with this process
//make sure to account for all
special cases
}
private Node start, end;
private int count;
public A3DoubleLL() {
start = end = null;
count = 0;
}
public String printList() {
String output = "";
Node current = start;
while(current != null) {
output +=
current.value + ",";
current =
current.next;
}
return output;
}
public String printListRev() {
String output = "";
Node current = end;
while(current != null) {
output +=
current.value + ",";
current =
current.prev;
}
return output;
}
public void add(E val) {
Node newItem = new Node(val);
if(start == null) {
start =
newItem;
end =
start;
count = 1;
} else {
end.next =
newItem;
newItem.prev =
end;
end =
newItem;
count++;
}
}
public void insert(E val, int index) {
if(index < 0) {//fix invalid
index
index = 0;
}
if(index >= count) {//goes in
last position
this.add(val);
} else {
Node newItem =
new Node(val);
if(index == 0)
{//goes in first position
newItem.next = start;
start.prev = newItem;
start = newItem;
} else {//goes
in middle
Node current = start;
for(int i = 1; i < index; i++) {
current = current.next;
}
newItem.next = current.next;
newItem.prev = current;
current.next.prev = newItem;
current.next = newItem;
}
count++;
}
}
public void delete(int index) {
if(index >= 0 && index
< count) {//valid index
if(index == 0)
{//remove first
start = start.next;
if(start != null) {//as long as there was an
item next in list
start.prev = null;
} else {//if only item was removed
end = null;
}
} else if(index
== count-1) {//remove last item
end = end.prev;
end.next = null;
} else {//remove
middle item
Node current = start;
for(int i = 1; i < index; i++) {
current = current.next;
}
current.next = current.next.next;
current.next.prev = current;
}
count--;
}
}
public E get(int index) {
if(index >= 0 && index
< count) {//valid index
Node current =
start;
for(int i = 0; i
< index; i++) {
current = current.next;
}
return
current.value;
}
return null;
}
public String toString() {
return this.printList();
}
private class Node {
E value;
Node next, prev;
public Node(E v) {
value = v;
next = prev =
null;
}
}
}
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
public class A3Driver {
public static void main(String[] args) {
A3DoubleLL<Integer> list =
new A3DoubleLL<>();
for(int i = 1; i < 10; i++)
{
list.add(i);
}
System.out.println("Before
Swap");
System.out.println(list.printList());
System.out.println(list.printListRev());
list.swap(4);
System.out.println("After
Swap");
System.out.println(list.printList()
+ ":1,2,3,4,6,5,7,8,9,");
System.out.println(list.printListRev() +
":9,8,7,6,5,4,3,2,1,");
System.out.println();
System.out.println("Hot
Potatoe");
A3CircleLL hotPotato = new
A3CircleLL();
hotPotato.playGame(5, 3);
System.out.println("Correct:");
System.out.println("Removed Player
4\nRemoved Player 3\nRemoved Player 5\nRemoved Player 2\nWinning
player is 1");
System.out.println();
A3Queue<Integer> queue = new
A3Queue<>();
queue.enqueue(5);
queue.enqueue(20);
queue.enqueue(15);
System.out.println(queue.peek()+":5");
System.out.println(queue.dequeue()+":5");
queue.enqueue(25);
System.out.println(queue.dequeue()+":20");
System.out.println(queue.dequeue()+":15");
}
}
In: Computer Science
Using Python.
In this question, you are expected to use TensorFlow and Keras to perform a deep learning process for creating an image classifier to distinguish between dog and cat. You should follow fchollet’s code to create the classifier and test this classifier with one test photo of dog and one test photo cat. Create a screenshot to show the classifying results of these two test photos. The dog and cat in the test photos should not be in your original training dataset, and you may use your own pets or your neighbor’s pets.
Thankyou
use this website for reference:
https://keras.io/examples/vision/image_classification_from_scratch/
In: Computer Science
Question about Java ArrayList:
how to delet congestive number:
eg : [1 2 2 3 2 2 1] -----> [1 2 3 2 1]
how to get the number that only in one list:
eg:
[2 2 1], [ 4 4 2 2], [8 8 4 4 2] -------->[1,8]
[8 8 4 4 2], [4 4 2 2], [2 2 1] --------->[1,8]
Thanks in advance
In: Computer Science
Java. Complete the methods for infixToPostfix, postfixToInfix, solvePostfix.
import java.util.Stack;
public class B1Work {
/*
* Grading:
* Correctly converts infix to postfix - 3pts
*/
public static String infixToPostfix(String infix)
{
/*
* Convert an infix math formula to
postfix format
* Infix format will always include
parens around any two values and a symbol
* You will not need to imply any
PEMDAS rules besides parens
* EXAMPLES:
* infix: (1+2) postfix: 12+
* infix: (1+(2-3)) postfix:
123-+
* infix: ((1+2)-3) postfix:
12+3-
* infix: ((1+2)-(3*4)) postfix:
12+34*-
*/
return null;
}
/*
* Grading:
* Correctly converts postfix to infix - 2pts
*/
public static String postfixToInfix(String postfix)
{
/*
* Convert a postfix math formula to
an infix format
* See above for conversion
examples
* Make sure to include parens in
the infix format
*/
return null;
}
/*
* Grading:
* Correctly solves postfix formulas with +-/* -
1pt
*/
public static double solvePostfix(String postfix)
{
Stack<Integer> stack = new
Stack<>();
/*
* Use a Stack to help solve a
postfix format formula for the numeric answer
* Order of operations is implied by
where symbols/numbers exist
* EXAMPLES
* postfix: 12+ = 3
* postfix: 123-+ = 0 :: 2-3 = -1 ::
1 + (-1) = 0
*/
return 0;
}
}
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
import java.util.Scanner;
public class B1Driver {
public static void main(String[] args) {
Scanner s = new
Scanner(System.in);
String format = "";
do {
System.out.print("What format will your formula be in
(infix/postfix):");
format =
s.nextLine().toLowerCase();
}while(!(format.equals("infix") ||
format.equals("postfix")));
System.out.print("Enter your
formula:");
String formula =
s.nextLine().replaceAll(" ", "");//removes whitespace
String infix, postfix;
switch(format) {
case "infix":
infix =
formula;
postfix =
B1Work.infixToPostfix(infix);
System.out.println("Infix:"+infix);
System.out.println("Postfix:"+postfix);
System.out.println("Answer:"+B1Work.solvePostfix(postfix));
break;
case "postfix":
postfix =
formula;
infix =
B1Work.postfixToInfix(postfix);
System.out.println("Infix:"+infix);
System.out.println("Postfix:"+postfix);
System.out.println("Answer:"+B1Work.solvePostfix(postfix));
break;
}
}
}
In: Computer Science
Java queue linked list
/*
* Complete the enqueue(E val) method
* Complete the dequeue() method
* Complete the peek() method
* No other methods/variables should be added/modified
*/
public class A3Queue {
/*
* Grading:
* Correctly adds an item to the queue - 1pt
*/
public void enqueue(E val) {
/*
* Add a node to the list
*/
}
/*
* Grading:
* Correctly removes an item from the queue - 1pt
* Handles special cases - 0.5pt
*/
public E dequeue() {
/*
* Remove a node from the list and
return it
*/
return null;
}
/*
* Grading:
* Correctly shows an item from the queue - 1pt
* Handles special cases - 0.5pt
*/
public E peek() {
/*
* Show a node from the list
*/
return null;
}
private Node front, end;
private int length;
public A3Queue() {
front = end = null;
length = 0;
}
private class Node {
E value;
Node next, prev;
public Node(E v) {
value = v;
next = prev =
null;
}
}
}
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
public class A3Driver {
public static void main(String[] args) {
A3Queue queue = new
A3Queue<>();
queue.enqueue(5);
queue.enqueue(20);
queue.enqueue(15);
System.out.println(queue.peek()+":5");
System.out.println(queue.dequeue()+":5");
queue.enqueue(25);
System.out.println(queue.dequeue()+":20");
System.out.println(queue.dequeue()+":15");
}
}
In: Computer Science
Indexing Arrays & Scalar Operations
Create a new array called “myShortArray” that contains the 1st, 3rd, and 5th elements of the array “myArray” as defined below using the indexing method.
myArray = [1, 2, 3, 4, 5, 6];
In: Computer Science
Insert the following data into an AVL tree and show the steps 10, 20, 30, 25, 40, 50, 35, 33, 37, 60, 38.
In: Computer Science
In: Computer Science
So currently I am working on some SQL with python which is linked to my database and I am stuck on a split problem. So in the program it connects to the database and then next you input either list, add, update, remove or allocate. So lets say I want to add a new data into the database you just need to write: update -name='Ava - #2' -class=2.
After you type this there is a variable called val which does the strip and split.
So as of right now what I have done is:
val = input('> ').strip().lower()
parts = val.split(' ')
print(parts)
So if I input the following: update -name="Nile Adam" -class=2
I expect the following output: ['update', '-name="Nile Adam"', '-class=2']
However the output I get is: ['update', '-name="Nile', 'Adam"', '-class=2']
In: Computer Science
Draw a flow chart for a program that will get the name and final exam results for all FBTOO15 students (474); and calculate the total scores for all students. After all results were entered, the average results would be calculated and displayed on screen.
In: Computer Science
In: Computer Science
C++ Program : You are working as a programmer designing a space ship weapon system for the newly
forced Space Force. The weapon system is a generic weapon housing that can t a number
of dierent weapons that are all controlled by a ship pilot in the same way. Most im-
portantly, is the emphasis on safety. During combat, the weapon systems cannot become
unreliable or fail lest the pilots be put in unnecessary danger. Therefore you will need to
provide mechanisms to combat this.
2.2.1 weaponMount
This is the mounting system for the weapons. It can store a number of weapons and
control them as well as handle problems. It is dened as follows:
weaponMount
-weapons:weapon **
-numWeapons: int
---------------------------
+weaponMount(numWeapons:int, weaponList: string *)
+~weaponMount()
+accessWeapon(i:int):weapon *
The class variables are as follows:
weapons: A 1D array of weapon pointers. It must be able to accept any type of
weapon dened in the hierarchy.
numWeapons: The number of weapons that are mounted into the system.
The class methods are as follows:
weaponMount: This is the constructor. It will receive a list of weapons as a string
array plus the number of weapons. It must allocate memory for the weapons variable
and create a weapon based on the information provided by the string array. Create
one weapon of the type indicated at each index of the array. For example ["Doom
Cannon","Ion Cannon"] means create a doomCannon weapon at index 0 and so on.
The default strength for an ion cannon is 5.
weaponMount: The class destructor. It must deallocate all of the memory assigned
to the class.
accessWeapon: This receives an int which provides an index in the weapons list. It
will return the weapon that is stored at that position. If no such weapon is found
there, then throw a weaponFailure exception.
2.2.2 weaponFailure
This is a custom exception class used in the context of this system. It will inherit publicly
from the exception class. You will need to override specically the what method to return
the statement "Weapon System Failure!" without the quotation marks. The name of this
class is weaponFailure. This exception will be used to indicate a failure of the weapon
system. You will implement this exception in the weaponMount class as a struct with
public access. You will need to research how to specify exceptions due to the potential
for a "loose throw specier error" and what clashes this might have with a compiler.
Remember that implementations of classes and structs must be done in .cpp les.
2.2.3 ammoOut
This is a custom exception class used in the context of this system. It will inherit publicly
from the exception class. You will need to override specically the what method to
return the statement "Ammo Depleted!" without the quotation marks. The name of this
class is ammoOut. This exception will be used to indicate a depletion of ammunition
for a weapon. You will implement this exception in the weapon class as a struct with
public access. You will need to research how to specify exceptions due to the potential
for a "loose throw specier error" and what clashes this might have with a compiler.
Remember that implementations of classes and structs must be done in .cpp les.
2.2.4 Weapon Parent Class
This is the parent class of ionCannon and doomCannon. Both of these classes inherit
publicly from it. It is dened according to the following UML diagram:
weapon
-ammo:int
-type:string
-------------------
+weapon()
+weapon(a:int, t:string)
+getAmmo():int
+getType():string
+setAmmo(s:int):void
+setType(s:string):void
+weapon()
+fire()=0:string
The class variables are as follows:
ammo: The amount of ammo stored in the weapon. As it is red, this will deplete.
type: The type of the weapon as a string. Examples include: "Rail Ri
Cannon","Doom Cannon", "Missile Launcher" and "Ion Cannon".
The class methods are as follows:
weapon: The default class constructor.
weapon(a:int, t:string): The constructor. It will take two arguments and instantiate
the class variables accordingly.
getAmmo,setAmmo: The getter and setter for the ammo.
getType,setType: The getter and setter for the ammo.
weapon: The destructor for the class. It is virtual.
fire: This is the method that will re each of the weapons and produce a string of
the outcome. It is pure virtual here.
2.2.5 ionCannon
The ionCannon is dened as follows:
ionCannon
-strength:int
------------------------------
+ionCannon(s:int)
+~ionCannon()
+setStrength(s:int):void
+getStrength() const:int
+fire():string
The class variables are as follows:
strength: The strength of the ion cannon. Ion cannons get stronger the longer they
are red.
The class methods are as follows:
ionCannon: The class constructor. This receives an initial strength for the ion
cannon.
ionCannon: This is the destructor for the ion cannon. It prints out "Ion Cannon
Uninstalled!" without the quotation marks and a new line at the end when the class
is deallocated.
fire: If the cannon still has ammo, it must decrease the ammo by 1. It will also
increase the strength by 1. It will return the following string: "Ion Cannon red at
strength: X" where X represents the strength before ring. Do not add quotation
marks. If ammo is not available, instead throw the ammoOut exception. No new
lines should be added.
getStrength/setStrength: The getter and setter for the strength variable.
2.2.6 doomCannon
The doomCannon is dened as follows:
doomCannon
-charge:int
------------------------------
+doomCannon()
+~doomCannon()
+getCharge():int
+setCharge(s:int):void
+fire():string
The class methods are as follows:
doomCannon: This is the constructor for the class. It will set the charge to 0.
doomCannon: This is the destructor for the ion cannon. It prints out "Doom
Cannon Uninstalled!" without the quotation marks and a new line at the end when
the class is deallocated.
setCharge/getCharge: The getter and setter for the charge variable.
re: The cannon can only re if it has ammo and only charge if it has ammo as
well. The charging process does not require ammo. Firing it will reduce the ammo
by 1. However the doom cannon requires a charging up period. Since the doom
cannon starts with 0 charge, it will not re until it reaches 5 charge, inclusive of the
5. Therefore every time it is red, it will increase in charge by 1. If the charge is not
at 5, then return the string "DOOM CANNON CHARGING" without quotation
marks. If the cannon starts at 5 charge when red reset the charge back to 0 and
return the following string: "DOOM CANNON FIRED!". Do not add quotation
marks. If ammo is not available, instead throw the ammoOut exception. No new
lines should be added.
You will be allowed to use the following libraries: sstream,exception, cstring,string,
iostream. Your submission must contain weaponMount.h, weaponMount.cpp, ionCannon.h, ionCannon.cpp, doom-
Cannon.h, doomCannon.cpp,weapon.h, weapon.cpp, main.cpp
In: Computer Science
Respond to the following in a minimum of 175 words:
Vulnerabilities can exist in both a business' software and hardware.
Discuss the differences between software and hardware vulnerabilities. How might these vulnerabilities impact a business
In: Computer Science
Recall the Kung and Robinson optimistic concurrency control algorithm. How can you modify that algorithm to ensure that every transaction eventually completes?
In: Computer Science