Question

Finish the code wherever it says TODO /**    * Node type for this list. Each...

Finish the code wherever it says TODO

/**
   * Node type for this list. Each node holds a maximum of nodeSize elements in an
   * array. Empty slots are null.
   */
   private class Node {
       /**
       * Array of actual data elements.
       */
       // Unchecked warning unavoidable.
       public E[] data = (E[]) new Comparable[nodeSize];

       /**
       * Link to next node.
       */
       public Node next;

       /**
       * Link to previous node;
       */
       public Node previous;

       /**
       * Index of the next available offset in this node, also equal to the number of
       * elements in this node.
       */
       public int count;

       /**
       * Adds an item to this node at the first available offset. Precondition: count
       * < nodeSize
       *
       * @param item element to be added
       */
       void addItem(E item) {
           if (count >= nodeSize) {
               return;
           }
           data[count++] = item;
           // useful for debugging
           // System.out.println("Added " + item.toString() + " at index " + count + " to
           // node " + Arrays.toString(data));
       }

       /**
       * Adds an item to this node at the indicated offset, shifting elements to the
       * right as necessary.
       *
       * Precondition: count < nodeSize
       *
       * @param offset array index at which to put the new element
       * @param item element to be added
       */
       void addItem(int offset, E item) {
           if (count >= nodeSize) {
               return;
           }
           for (int i = count - 1; i >= offset; --i) {
               data[i + 1] = data[i];
           }
           ++count;
           data[offset] = item;
           // useful for debugging
// System.out.println("Added " + item.toString() + " at index " + offset + " to node: " + Arrays.toString(data));
       }

       /**
       * Deletes an element from this node at the indicated offset, shifting elements
       * left as necessary. Precondition: 0 <= offset < count
       *
       * @param offset
       */
       void removeItem(int offset) {
           E item = data[offset];
           for (int i = offset + 1; i < nodeSize; ++i) {
               data[i - 1] = data[i];
           }
           data[count - 1] = null;
           --count;
       }
   }

   private class StoutListIterator implements ListIterator<E> {
       // constants you possibly use ...

       // instance variables ...

       /**
       * Default constructor
       */
       public StoutListIterator() {
           // TODO
       }

       /**
       * Constructor finds node at a given position.
       *
       * @param pos
       */
       public StoutListIterator(int pos) {
           // TODO
       }

       @Override
       public boolean hasNext() {
           // TODO
       }

       @Override
       public E next() {
           // TODO
       }

       @Override
       public void remove() {
           // TODO
       }

       // Other methods you may want to add or override that could possibly facilitate
       // other operations, for instance, addition, access to the previous element,
       // etc.
       //
       // ...
       //
   }

   /**
   * Sort an array arr[] using the insertion sort algorithm in the NON-DECREASING
   * order.
   *
   * @param arr array storing elements from the list
   * @param comp comparator used in sorting
   */
   private void insertionSort(E[] arr, Comparator<? super E> comp) {
       // TODO
   }

   /**
   * Sort arr[] using the bubble sort algorithm in the NON-INCREASING order. For a
   * description of bubble sort please refer to Section 6.1 in the project
   * description. You must use the compareTo() method from an implementation of
   * the Comparable interface by the class E or ? super E.
   *
   * @param arr array holding elements from the list
   */
   private void bubbleSort(E[] arr) {
       // TODO
   }

}

Homework Answers

Answer #1

1

So I need to remove empty (undefined) items from the multidimensional array. Atm my code looks like this (it's a method I run so that's why i am using this:

f: function(arr) {
    var __ = this;
    arr = arr.filter(function(item) {
        return Array.isArray(item) ? __.f(item) : typeof(item) !== "undefined";
    });
return arr;
}

but if i run console.log(myObject.f([1, 2, , , , , 3, 4, [5, , , , , ], 6, , , , 8, 3, [[[], 9]]])); i get [ 1, 2, 3, 4, [ 5, , , , ], 6, 8, 3, [ [ [], 9 ] ] ] and that is kinda weird result. I goes pretty well for the first layer but removes only one undefined from inner layers. Also I would like to remove a subarray that consists of no items.

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Java : Modify the selection sort algorithm to sort an array of integers in descending order....
Java : Modify the selection sort algorithm to sort an array of integers in descending order. describe how the skills you have gained could be applied in the field. Please don't use an already answered solution from chegg. I've unfortunately had that happen at many occasion ....... ........ sec01/SelectionSortDemo.java import java.util.Arrays; /** This program demonstrates the selection sort algorithm by sorting an array that is filled with random numbers. */ public class SelectionSortDemo { public static void main(String[] args) {...
Assignment 1 - ITSC 2214 I have to complete the array list for a shopping list...
Assignment 1 - ITSC 2214 I have to complete the array list for a shopping list code and can't figure out how to complete it: Below is the code Complete the three empty methods (remove(), find(), and contains()) in the ShoppingListArrayList.java file. These methods are already implemented in the ShoppingListArray class. /////////////////////////////////////////////////////////////////////////////////////////////////////////// Grocery Class (If this helps) package Shopping; public class Grocery implements Comparable<Grocery> { private String name; private String category; private int aisle; private float price; private int quantity;...
Code in JAVA The requirements are as follows: The input will be in a text file...
Code in JAVA The requirements are as follows: The input will be in a text file whose name is given by arg[0] of main(). It will contain a fully-parenthesized infix expression containing only: "(", ")", "+", "-" and integers. Need help on the main and fixing the Queue. //Input: ( ( 1 + 2 ) - ( ( 3 - 4 ) + ( 7 - 2 ) ) ) ( ( 1 + 2 ) - ( 3 -...
Please explain code 1 and code 2 for each lines code 1 public class MyQueue {...
Please explain code 1 and code 2 for each lines code 1 public class MyQueue {    public static final int DEFAULT_SIZE = 10;    private Object data[];    private int index; code 2 package test; import java.util.*; /* Class Node */ class Node { protected Object data; protected Node link; /* Constructor */ public Node() { link = null; data = 0; } /* Constructor */ public Node(Object d,Node n) { data = d; link = n; } /*...
In this code, I build a single-linked list using a node class that has been created....
In this code, I build a single-linked list using a node class that has been created. How could I change this code to take data of type T, rather than int. (PS: ignore the fact that IOHelper.getInt won't work for the type T... ie second half of main). Here's my code right now: public class SLList { public SLNode head = null; public SLNode tail = null; public void add(int a) {// add() method present for testing purposes SLNode newNode...
My assignment: Triplet Template Class Directions: Define a template class for a generic triplet. The private...
My assignment: Triplet Template Class Directions: Define a template class for a generic triplet. The private data member for the triplet is a generic array with three elements. The triplet ADT has the following functions:  default constructor  explicit constructor: initialize the data member using parameters  three accessors (three get functions) which will return the value of each individual element of the array data member  one mutator (set function) which will assign values to the data member...
Do a theta analysis and count the number of computations it performed in each function/method of...
Do a theta analysis and count the number of computations it performed in each function/method of the following code: import java.io.*; import java.util.Scanner; class sort { int a[]; int n; long endTime ; long totalTime; long startTime; static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); public sort(int nn) // Constructor { a = new int[nn]; n = nn; endTime= 0; totalTime =0; startTime =0; } public static void main(String args[]) throws IOException { System.out.print("\nEnter number of students: "); int nn =...
This is the java code that I have, but i cannot get the output that I...
This is the java code that I have, but i cannot get the output that I want out of it. i want my output to print the full String Form i stead of just the first letter, and and also print what character is at the specific index instead of leaving it empty. and at the end for Replaced String i want to print both string form one and two with the replaced letters instead if just printing the first...
(JAVA) Why is my toString method not printing out the last node? It will not print...
(JAVA) Why is my toString method not printing out the last node? It will not print out "A" which is for Alice. Everything else is working just fine except for this. package driver; import exception.StackException; import stack.*; public class StackDriver { public static void main(String[] args) throws Exception { StackInterface<Painting> painting = new LinkedStack <Painting>(); try { System.out.println("Peeking at top of player stack.\n" + painting.peek()); }catch (StackException e) { System.out.println(e); System.out.println("Let's double check if it's empty: " + painting.isEmpty()); }...
Task 1: You will modify the add method in the LinkedBag class.Add a second parameter to...
Task 1: You will modify the add method in the LinkedBag class.Add a second parameter to the method header that will be a boolean variable: public boolean add(T newEntry, boolean sorted) The modification to the add method will makeit possible toadd new entriesto the beginning of the list, as it does now, but also to add new entries in sorted order. The sorted parameter if set to false will result in the existing functionality being executed (it will add the...