redcaribou896

redcaribou896

Lv2

0 Followers
0 Following
0 Helped

ANSWERS

Published28

Subjects

Business2Electrical Engineering2Mechanical Engineering2Algebra7Engineering3Geometry1Computer Science3Calculus3Physics2Finance1Chemistry2
Answer: Step-by-step explanation: If S, T : V -> V are linear operators suc...
Answer: Step-by-step explanation: a) We can find the maximum height reached by...
Answer: Step-by-step explanation: To solve these problems algebraically, we ca...
Answer: Step-by-step explanation: To solve these problems algebraically, we ca...
Answer: Step-by-step explanation: To automate Azure-related tasks in a GitHub ...
Answer: Step-by-step explanation: To determine the Kp for this reaction, we ne...
Answer: (a) Yes, there is at least one point along the path of a projectile wh...
Answer: (a)TrueFalse (b)TrueFalse (c)TrueFalse Step-by-step explanation: Here ...
Answer: It is not possible to answer the questions without the data that is me...
Answer:(x*tan(x))' = sin(x)*(1 - x)/cos^2(x) Step-by-step explanation: To diff...
Answer: Step-by-step explanation: Here are some rules for differentiating alge...
Answer: The Huffman code for the string "cabcedeacadeddaaaba" is: 000100101011...

import java.io.PrintStream;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.Iterator;
import java.util.NoSuchElementException;

public class P4Wrapper {

Ā // List
Ā public interface List<E> extends Iterable<E> {
Ā Ā 
Ā  public int size();
Ā Ā 
Ā  public boolean isEmpty();
Ā Ā 
Ā  public boolean isMember(E e);

Ā  public void add(E e);
Ā Ā 
Ā  public void add(E e, int index);
Ā Ā 
Ā  public E first();
Ā Ā 
Ā  public E last();
Ā Ā 
Ā  public int firstIndex(E e);
Ā Ā 
Ā  public int lastIndex(E e);
Ā Ā 
Ā  public E get(int index);
Ā Ā 
Ā  public E replace(E e, int index);
Ā Ā 
Ā  public E remove(int index);
Ā Ā 
Ā  public boolean remove(E e);
Ā Ā 
Ā  public int removeAll(E e);
Ā Ā 
Ā  public void clear();
Ā Ā 
Ā  public Object[] toArray();
Ā Ā 

Ā }
Ā 
Ā 
Ā ///////////////////// SinglyLinkedList
Ā ///////////
Ā public static class SinglyLinkedList<E> implements List<E> {
Ā Ā 
Ā  @SuppressWarnings("hiding")
Ā  private class SinglyLinkedListIterator<E> implements Iterator<E>{
Ā  Ā 
Ā  Ā private Node<E> nextNode;
Ā  Ā 

Ā  Ā @SuppressWarnings("unchecked")
Ā  Ā public SinglyLinkedListIterator() {
Ā  Ā  super();
Ā  Ā  this.nextNode = (Node<E>) header.getNext();
Ā  Ā }

Ā  Ā @Override
Ā  Ā public boolean hasNext() {
Ā  Ā  return this.nextNode != null;
Ā  Ā }

Ā  Ā @Override
Ā  Ā public E next() {
Ā  Ā  if (this.hasNext()) {
Ā  Ā  Ā E result = this.nextNode.getElement();
Ā  Ā  Ā this.nextNode = this.nextNode.getNext();
Ā  Ā  Ā return result;
Ā  Ā  }
Ā  Ā  else {
Ā  Ā  Ā throw new NoSuchElementException();
Ā  Ā  }
Ā  Ā }
Ā  Ā 
Ā  }
Ā Ā 
Ā Ā 
Ā  // node class
Ā  private static class Node<E>{
Ā  Ā private E element;
Ā  Ā private Node<E> next;
Ā  Ā public Node(E element, Node<E> next) {
Ā  Ā  super();
Ā  Ā  this.element = element;
Ā  Ā  this.next = next;
Ā  Ā }
Ā  Ā public Node() {
Ā  Ā  super();
Ā  Ā  this.element = null;
Ā  Ā  this.next = null;
Ā  Ā 
Ā  Ā }
Ā  Ā public E getElement() {
Ā  Ā  return element;
Ā  Ā }
Ā  Ā public void setElement(E element) {
Ā  Ā  this.element = element;
Ā  Ā }
Ā  Ā public Node<E> getNext() {
Ā  Ā  return next;
Ā  Ā }
Ā  Ā public void setNext(Node<E> next) {
Ā  Ā  this.next = next;
Ā  Ā }
Ā  Ā 
Ā  Ā 
Ā  }
Ā Ā 
Ā  // private fields
Ā  private Node<E> header;
Ā  private int currentSize;
Ā Ā 
Ā Ā 

Ā  public SinglyLinkedList() {
Ā  Ā this.header = new Node<>();
Ā  Ā this.currentSize = 0;
Ā  Ā 
Ā  }

Ā  @Override
Ā  public Iterator<E> iterator() {
Ā  Ā return new SinglyLinkedListIterator<E>();
Ā  }

Ā  @Override
Ā  public int size() {
Ā  Ā return this.currentSize;
Ā  }

Ā  @Override
Ā  public boolean isEmpty() {
Ā  Ā return this.size() == 0;
Ā  }

Ā  @Override
Ā  public boolean isMember(E e) {
Ā  Ā return this.firstIndex(e) >= 0;
Ā  }

Ā  @Override
Ā  public void add(E e) {
Ā  Ā 
Ā  Ā Node<E> temp = this.header;
Ā  Ā while (temp.getNext() != null) {
Ā  Ā  temp = temp.getNext();
Ā  Ā }
Ā  Ā temp.setNext(new Node<E>(e, null));
Ā  Ā this.currentSize++;
Ā  Ā 
Ā  Ā // cool
Ā  Ā //this.getPosition(this.size() -1).setNext(new Node<E>(e, null));
Ā  Ā //this.currentSize++;
Ā  }

Ā  @Override
Ā  public void add(E e, int index) {
Ā  Ā if ((index <0) || (index > this.size())){
Ā  Ā  throw new IndexOutOfBoundsException();
Ā  Ā }
Ā  Ā if (index == this.size()) {
Ā  Ā  this.add(e);
Ā  Ā }
Ā  Ā else {
Ā  Ā  Node<E> temp = null;Ā 
Ā  Ā  if (index == 0) {
Ā  Ā  Ā temp = this.header;
Ā  Ā  }
Ā  Ā  else {
Ā  Ā  Ā temp = this.getPosition(index -1);
Ā  Ā  }
Ā  Ā  // add new node
Ā  Ā  Node<E> newNode = new Node<>();
Ā  Ā  newNode.setElement(e);
Ā  Ā  newNode.setNext(temp.getNext());
Ā  Ā  temp.setNext(newNode);
Ā  Ā  this.currentSize++;
Ā  Ā }
Ā  }

Ā  @Override
Ā  public E first() {
Ā  Ā if (this.isEmpty()) {
Ā  Ā  return null;
Ā  Ā }
Ā  Ā else {
Ā  Ā  return this.header.getNext().getElement();
Ā  Ā }
Ā  }

Ā  @Override
Ā  public E last() {
Ā  Ā if (this.isEmpty()) {
Ā  Ā  return null;
Ā  Ā }
Ā  Ā else {
Ā  Ā  Node<E> temp = this.header.getNext();
Ā  Ā  while (temp.getNext() != null) {
Ā  Ā  Ā temp = temp.getNext();
Ā  Ā  }
Ā  Ā  Ā  Ā Ā 
Ā  Ā  return temp.getElement();Ā 
Ā  Ā }
Ā  }

Ā  @Override
Ā  public int firstIndex(E e) {
Ā  Ā int currentPosition = 0;
Ā  Ā Node<E> temp = this.header.getNext();
Ā  Ā 
Ā  Ā while(temp != null) {
Ā  Ā  if (temp.getElement().equals(e)) {
Ā  Ā  Ā return currentPosition;
Ā  Ā  }
Ā  Ā  else {
Ā  Ā  Ā temp = temp.getNext();
Ā  Ā  Ā currentPosition++;
Ā  Ā  }
Ā  Ā }
Ā  Ā return -1;
Ā  Ā 
Ā  }

Ā  @Override
Ā  public int lastIndex(E e) {
Ā  Ā int i=0;
Ā  Ā int lastIndex = -1;
Ā  Ā Node<E> temp = this.header.getNext();
Ā  Ā while (temp != null) {
Ā  Ā  if (temp.getElement().equals(e)) {
Ā  Ā  Ā lastIndex = i;
Ā  Ā  }
Ā  Ā  i++;
Ā  Ā  temp = temp.getNext();
Ā  Ā }
Ā  Ā return lastIndex;
Ā  }
Ā Ā 
Ā  private Node<E> getPosition(int index){
Ā  Ā int currentPosition = 0;
Ā  Ā Node<E> temp = this.header.getNext();
Ā  Ā 
Ā  Ā while (currentPosition != index) {
Ā  Ā  temp = temp.getNext();
Ā  Ā  currentPosition++;
Ā  Ā }
Ā  Ā return temp;
Ā  }

Ā  @Override
Ā  public E get(int index) {
Ā  Ā if ((index <0) || (index >= this.currentSize)) {
Ā  Ā  throw new IndexOutOfBoundsException();
Ā  Ā }
Ā  Ā return this.getPosition(index).getElement();
Ā  }

Ā  @Override
Ā  public E replace(E e, int index) {
Ā  Ā if ((index <0) || (index >= this.currentSize)) {
Ā  Ā  throw new IndexOutOfBoundsException();
Ā  Ā }
Ā  Ā Node<E> temp = this.getPosition(index);
Ā  Ā E result = temp.getElement();
Ā  Ā temp.setElement(e);
Ā  Ā return result;
Ā  }

Ā  @Override
Ā  public E remove(int index) {
Ā  Ā if ((index < 0) || (index >= this.currentSize)){
Ā  Ā  throw new IndexOutOfBoundsException();
Ā  Ā }
Ā  Ā int currentPosition =0;
Ā  Ā Node<E> temp = this.header;
Ā  Ā while(currentPosition != index) {
Ā  Ā  temp = temp.getNext();
Ā  Ā  currentPosition++;
Ā  Ā }
Ā  Ā Node<E> target = temp.getNext();
Ā  Ā E result = target.getElement();
Ā  Ā temp.setNext(target.getNext());
Ā  Ā target.setElement(null);
Ā  Ā target.setNext(null);
Ā  Ā this.currentSize--;
Ā  Ā return result;

Ā  }

Ā  @Override
Ā  public boolean remove(E e) {
Ā  Ā int target = this.firstIndex(e);
Ā  Ā if (target < 0) {
Ā  Ā  return false;
Ā  Ā }
Ā  Ā else {
Ā  Ā  this.remove(target);
Ā  Ā  return true;
Ā  Ā }
Ā  }

Ā  @Override
Ā  public int removeAll(E e) {
Ā  Ā int count = 0;
Ā  Ā while (this.remove(e)) {
Ā  Ā  count++;
Ā  Ā }
Ā  Ā return count;
Ā  }

Ā  @Override
Ā  public void clear() {
Ā  Ā while(!this.isEmpty()) {
Ā  Ā  this.remove(0);
Ā  Ā }

Ā  }

Ā  @Override
Ā  public Object[] toArray() {
Ā  Ā Object[] result = new Object[this.size()];
Ā  Ā for (int i=0; i < this.size(); ++i) {
Ā  Ā  result[i]= this.get(i);
Ā  Ā }
Ā  Ā return result;
Ā  }

Ā }
Ā 
Ā /////////////// Ā MAP
Ā ////
Ā public interface Map<K, V> {
Ā Ā 
Ā  public int size();
Ā Ā 
Ā  public boolean isEmpty();
Ā Ā 
Ā  public V get(K key);
Ā Ā 
Ā  public V put(K key, V value);
Ā Ā 
Ā  public V remove(K key);
Ā Ā 
Ā  public boolean contains(K key);
Ā Ā 
Ā  public List<K> getKeys();
Ā Ā 
Ā  public List<V> getValues();Ā 

Ā }
Ā 
Ā ////// Tree Node
Ā public interface TreeNode<E> {
Ā Ā 
Ā  public E getValue();

Ā }
Ā 
Ā 
Ā /////////
Ā // Binary Tree Node
Ā public interface BinaryTreeNode<E> extends TreeNode<E> {
Ā Ā 
Ā  public BinaryTreeNode<E> getLeftChild();
Ā Ā 
Ā  public BinaryTreeNode<E> getRightChild();
Ā Ā 
Ā  public BinaryTreeNode<E> getParent();
Ā Ā 

Ā }

Ā //////
Ā /// BinaryTreeNodeImp
Ā 
Ā public static class BinaryTreeNodeImp<E> implements BinaryTreeNode<E> {
Ā Ā 
Ā  private E value;
Ā Ā 
Ā  private BinaryTreeNode<E> Ā leftChild;
Ā  private BinaryTreeNode<E> Ā rightChild;
Ā  private BinaryTreeNode<E> Ā parent;


Ā  public BinaryTreeNodeImp(E value, BinaryTreeNode<E> leftChild, BinaryTreeNode<E> rightChild,
Ā  Ā  BinaryTreeNode<E> parent) {
Ā  Ā super();
Ā  Ā this.value = value;
Ā  Ā this.leftChild = leftChild;
Ā  Ā this.rightChild = rightChild;
Ā  Ā this.parent = parent;
Ā  }

Ā  @Override
Ā  public E getValue() {
Ā  Ā return this.value;
Ā  }

Ā  @Override
Ā  public BinaryTreeNode<E> getLeftChild() {
Ā  Ā return this.leftChild;
Ā  }

Ā  @Override
Ā  public BinaryTreeNode<E> getRightChild() {
Ā  Ā return this.rightChild;
Ā  }

Ā  @Override
Ā  public BinaryTreeNode<E> getParent() {
Ā  Ā return this.parent;
Ā  }

Ā  public void setValue(E value) {
Ā  Ā this.value = value;
Ā  }

Ā  public void setLeftChild(BinaryTreeNode<E> leftChild) {
Ā  Ā this.leftChild = leftChild;
Ā  }

Ā  public void setRightChild(BinaryTreeNode<E> rightChild) {
Ā  Ā this.rightChild = rightChild;
Ā  }

Ā  public void setParent(BinaryTreeNode<E> parent) {
Ā  Ā this.parent = parent;
Ā  }


Ā }
Ā 
Ā ////// Key Value Pair
Ā public interface KeyValuePair<K, V> {
Ā Ā 
Ā  public K getKey();
Ā  public V getValue();

Ā }
Ā 
Ā 
Ā /// Binary Search Tree
Ā public static class BinarySearchTree<K, V> implements Map<K, V> {
Ā Ā 
Ā  // MapEntry class implements KeyValuePair
Ā Ā 
Ā  private static class MapEntry<K,V> implements KeyValuePair<K,V> {
Ā  Ā private K key;
Ā  Ā private V value;
Ā  Ā 
Ā  Ā 
Ā  Ā public MapEntry(K key, V value) {
Ā  Ā  super();
Ā  Ā  this.key = key;
Ā  Ā  this.value = value;
Ā  Ā }
Ā  Ā public K getKey() {
Ā  Ā  return key;
Ā  Ā }
Ā  Ā @SuppressWarnings("unused")
Ā  Ā public void setKey(K key) {
Ā  Ā  this.key = key;
Ā  Ā }
Ā  Ā public V getValue() {
Ā  Ā  return value;
Ā  Ā }
Ā  Ā @SuppressWarnings("unused")
Ā  Ā public void setValue(V value) {
Ā  Ā  this.value = value;
Ā  Ā } Ā 

Ā  }
Ā  Ā 
Ā Ā 
Ā  private int currentSize;
Ā  private BinaryTreeNode<MapEntry<K,V>> root;
Ā  private Comparator<K> keyComparator;
Ā Ā 
Ā  public BinarySearchTree(Comparator<K> keyComparator) {
Ā  Ā this.root = null;
Ā  Ā this.currentSize = 0;
Ā  Ā this.keyComparator = keyComparator;
Ā  }

Ā  @Override
Ā  public int size() {
Ā  Ā return this.currentSize;
Ā  }

Ā  @Override
Ā  public boolean isEmpty() {
Ā  Ā return this.size() == 0;
Ā  }

Ā  @Override
Ā  public V get(K key) {
Ā  Ā return this.getAux(key, this.root);
Ā  Ā 
Ā  }

Ā  private V getAux(K key, BinaryTreeNode<MapEntry<K, V>> N) {
Ā  Ā if (N == null) {
Ā  Ā  return null; // not found
Ā  Ā }
Ā  Ā else {
Ā  Ā  int comparison = this.keyComparator.compare(key, N.getValue().getKey());
Ā  Ā  if (comparison == 0) {
Ā  Ā  Ā return N.getValue().getValue();
Ā  Ā  }
Ā  Ā  else if (comparison < 0) {
Ā  Ā  Ā return this.getAux(key, N.getLeftChild());
Ā  Ā  }
Ā  Ā  else {
Ā  Ā  Ā return this.getAux(key, N.getRightChild());
Ā  Ā  }
Ā  Ā }
Ā  }

Ā  @Override
Ā  public V put(K key, V value) {
Ā  Ā if (this.root == null) {
Ā  Ā  MapEntry<K,V> M = new MapEntry<K,V>(key, value);
Ā  Ā  this.root = newĀ 
Ā  Ā  Ā  BinaryTreeNodeImp<MapEntry<K,V>>(M, null, null, null);
Ā  Ā  this.currentSize++;
Ā  Ā  return value;
Ā  Ā }
Ā  Ā else {
Ā  Ā  return this.putAux(key, value, (BinaryTreeNodeImp<MapEntry<K, V>>) this.root);
Ā  Ā }
Ā  }

Ā  private V putAux(K key, V value, BinaryTreeNodeImp<MapEntry<K, V>> N) {
Ā  Ā int comparison = this.keyComparator.compare(key, Ā N.getValue().getKey());
Ā  Ā if (comparison < 0) {
Ā  Ā  // left
Ā  Ā  if (N.getLeftChild() == null) {
Ā  Ā  Ā MapEntry<K,V> M = new MapEntry<K,V>(key, value);
Ā  Ā  Ā BinaryTreeNodeImp<MapEntry<K,V>> newNode =
Ā  Ā  Ā  Ā new BinaryTreeNodeImp<MapEntry<K,V>>Ā 
Ā  Ā  Ā (M, null, null, N);
Ā  Ā  Ā N.setLeftChild(newNode);
Ā  Ā  Ā this.currentSize++;
Ā  Ā  Ā return value;
Ā  Ā  }
Ā  Ā  else {
Ā  Ā  Ā return this.putAux(key, value,Ā 
Ā  Ā  Ā  Ā (BinaryTreeNodeImp<MapEntry<K, V>>) N.getLeftChild());
Ā  Ā  }
Ā  Ā }
Ā  Ā else {
Ā  Ā  // right
Ā  Ā  if (N.getRightChild() == null) {
Ā  Ā  Ā MapEntry<K,V> M = new MapEntry<K,V>(key, value);
Ā  Ā  Ā BinaryTreeNodeImp<MapEntry<K,V>> newNode =
Ā  Ā  Ā  Ā new BinaryTreeNodeImp<MapEntry<K,V>>Ā 
Ā  Ā  Ā (M, null, null, N);
Ā  Ā  Ā N.setRightChild(newNode);
Ā  Ā  Ā this.currentSize++;
Ā  Ā  Ā return value;
Ā  Ā  }
Ā  Ā  else {
Ā  Ā  Ā return this.putAux(key, value,Ā 
Ā  Ā  Ā  Ā (BinaryTreeNodeImp<MapEntry<K, V>>) N.getRightChild());
Ā  Ā  }
Ā  Ā Ā 
Ā  Ā }
Ā  }

Ā  @Override
Ā  public V remove(K key) {
Ā  Ā if (this.root == null) {
Ā  Ā  return null;
Ā  Ā }
Ā  Ā else {
Ā  Ā  int comparison = this.keyComparator.compare(key, this.root.getValue().getKey());
Ā  Ā  if (comparison == 0) {
Ā  Ā  Ā // remove from root
Ā  Ā  Ā if (this.isLeaf(this.root)) {
Ā  Ā  Ā  V result = this.root.getValue().getValue();
Ā  Ā  Ā  ((BinaryTreeNodeImp<MapEntry<K, V>>) this.root).setValue(null);
Ā  Ā  Ā  this.root = null;
Ā  Ā  Ā  this.currentSize--;
Ā  Ā  Ā  return result;
Ā  Ā  Ā Ā 
Ā  Ā  Ā }
Ā  Ā  Ā else if (this.root.getRightChild() == null) {
Ā  Ā  Ā  V result = this.root.getValue().getValue();
Ā  Ā  Ā  this.root = this.root.getLeftChild();
Ā  Ā  Ā  this.currentSize--;
Ā  Ā  Ā  return result;
Ā  Ā  Ā }
Ā  Ā  Ā else {
Ā  Ā  Ā  V result = this.root.getValue().getValue();
Ā  Ā  Ā  BinaryTreeNodeImp<MapEntry<K, V>> S =Ā 
Ā  Ā  Ā  Ā  this.smallestChild((BinaryTreeNodeImp<MapEntry<K, V>>) this.root.getRightChild());
Ā  Ā  Ā  ((BinaryTreeNodeImp<MapEntry<K, V>>) this.root).setValue(S.getValue());;
Ā  Ā  Ā  this.removeAux(S.getValue().getKey(), this.root.getRightChild());
Ā  Ā  Ā  return result;
Ā  Ā  Ā }
Ā  Ā  }
Ā  Ā  else if (comparison < 0) {
Ā  Ā  Ā // remove from left
Ā  Ā  Ā return this.removeAux(key, this.root.getLeftChild());
Ā  Ā  }
Ā  Ā  else {
Ā  Ā  Ā //remove right
Ā  Ā  Ā return this.removeAux(key, this.root.getRightChild());

Ā  Ā  }
Ā  Ā }
Ā  }

Ā  private boolean isLeaf(BinaryTreeNode<MapEntry<K, V>> N) {
Ā  Ā return N.getLeftChild() == null && N.getRightChild() == null;
Ā  }

Ā  private V removeAux(K key, BinaryTreeNode<MapEntry<K, V>> N) {
Ā  Ā // TODO Auto-generated method stub
Ā  Ā return null;
Ā  }

Ā  private BinaryTreeNodeImp<MapEntry<K, V>> smallestChild(
Ā  Ā  BinaryTreeNodeImp<MapEntry<K, V>> N) {
Ā  Ā BinaryTreeNodeImp<MapEntry<K, V>> temp = N;
Ā  Ā 
Ā  Ā while (temp.getLeftChild() != null) {
Ā  Ā  temp = (BinaryTreeNodeImp<MapEntry<K, V>>) temp.getLeftChild();
Ā  Ā }
Ā  Ā return temp;
Ā  Ā 
Ā  }
Ā  @Override
Ā  public boolean contains(K key) {
Ā  Ā return this.get(key) != null;
Ā  }

Ā  @Override
Ā  public List<K> getKeys() {
Ā  Ā List<K> result = new SinglyLinkedList<K>();
Ā  Ā this.getKeysAux(this.root, result);
Ā  Ā return result;
Ā  Ā 
Ā  }

Ā  private void getKeysAux(BinaryTreeNode<MapEntry<K, V>> N, List<K> result) {
Ā  Ā if (N == null) {
Ā  Ā  return;
Ā  Ā }
Ā  Ā else {
Ā  Ā  this.getKeysAux(N.getLeftChild(), result);
Ā  Ā  result.add(N.getValue().getKey());
Ā  Ā  this.getKeysAux(N.getRightChild(), result);
Ā  Ā }
Ā  }

Ā  @Override
Ā  public List<V> getValues() {
Ā  Ā List<V> result = new SinglyLinkedList<V>();
Ā  Ā this.getValuesAux(this.root, result);
Ā  Ā return result;
Ā  Ā 

Ā  }

Ā  private void getValuesAux(BinaryTreeNode<MapEntry<K, V>> N, List<V> result) {
Ā  Ā if (N == null) {
Ā  Ā  return;
Ā  Ā }
Ā  Ā else {
Ā  Ā  this.getValuesAux(N.getLeftChild(), result);
Ā  Ā  result.add(N.getValue().getValue());
Ā  Ā  this.getValuesAux(N.getRightChild(), result);
Ā  Ā }
Ā  Ā 
Ā  }

Ā  public void print(PrintStream out) {
Ā  Ā printAux(this.root, out, 0);
Ā  Ā 
Ā  Ā 
Ā  }
Ā Ā 
Ā  public void printAux(BinaryTreeNode<MapEntry<K, V>> N,Ā 
Ā  Ā  PrintStream out, int spaces) {
Ā  Ā if (N == null) {
Ā  Ā  return;
Ā  Ā }
Ā  Ā else {
Ā  Ā  printAux(N.getRightChild(), out, spaces + 4);
Ā  Ā  // print this values
Ā  Ā  for (int i=0; i< spaces; ++i) {
Ā  Ā  Ā out.print(" ");
Ā  Ā  }
Ā  Ā  out.println(N.getValue().getKey());
Ā  Ā  printAux(N.getLeftChild(), out, spaces + 4);
Ā  Ā Ā 
Ā  Ā }
Ā  }

Ā }
Ā 
Ā 
Ā ////Ā 
Ā /// Integer Comparator
Ā public static class IntegerComparator implements Comparator<Integer> {
Ā Ā 
Ā  public IntegerComparator() {
Ā  Ā 
Ā  }

Ā  @Override
Ā  public int compare(Integer o1, Integer o2) {
Ā  Ā return o1.compareTo(o2);
Ā  }
Ā Ā 
Ā }
Ā /////////////////////////////////////////////////////////////////////////////////////////////
Ā //// Ā  FOR STUDENTSĀ 
Ā //Ā 
Ā 
Ā /*
Ā  * Write a non-member method named findNLargestValues. This method finds N largest values in a
Ā  * Java array list of integers, and returns them in a new Java array list. The method receives as parameter
Ā  * the array list with the original integer data, and the number N. It returns an array list the N largest
Ā  * values, ORDERED from largest to smallest.
Ā  * Hint: Use a Binary Search Tree to organize the data.
Ā  */
Ā public static ArrayList<Integer> findNLargestValues(ArrayList<Integer> data, int N){
Ā  Ā return null;
Ā }
}

Answer: It looks like this is a Java program that defines several classes rela...
Answer: Step-by-step explanation: a) The dry unit weight of soil is the weight...
Answer: Step-by-step explanation: The flow rate of the distillate stream is 10...
Answer: if x=15, then z=1.875.Step-by-step explanation: If y varies directly a...
Answer: Step-by-step explanation: To write the equation of a quadratic functio...
Answer: Step-by-step explanation: To solve this problem, we need to find the t...
Answer: Step-by-step explanation: To solve part (a) of this problem, we need t...
Answer: Step-by-step explanation: Trade barriers are measures or restrictions ...
Answer: Step-by-step explanation: In order to solve this problem, we can use t...
Answer: Step-by-step explanation: The Energy Conservation Act, 2001 is a legis...
Answer: Step-by-step explanation: The speed of light in a vacuum is approximat...
Answer: Step-by-step explanation: The set difference of A and B is denoted as ...
Answer: Step-by-step explanation: To find the revenue function R(x), we need t...
Answer: Step-by-step explanation: a) For Joan's basketball, the initial veloci...
Answer: Step-by-step explanation: a) Convert mass to moles for the reactants C...
Answer:The reaction forces in a beam are the forces exerted on the beam by the...

Weekly leaderboard

Start filling in the gaps now
Log in