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
Complete the java code as per the comments public class Sorting {    ///////////////////////////////////////////////    //...
Complete the java code as per the comments public class Sorting {    ///////////////////////////////////////////////    // STEP 1 -- Make sorting methods generic    ///////////////////////////////////////////////       /**    * Re-orders the contents given array using the insertion sort algorithm.    *    * @param data The array to be sorted.    */    //TODO: Make me generic to work on any kind of Comparable data!    public static void insertionSort(int[] data)    {        int insert; // temporary...
I need to get the Min and Max value of an array when a user inputs...
I need to get the Min and Max value of an array when a user inputs values into the array. problem is, my Max value is right but my min value is ALWAYS 0. how do i fix this? any help please!!! _________________________________________________________________________________________________ import java.util.Scanner; public class ArrayMenu{ static int count; static Scanner kb = new Scanner(System.in);             public static void main(){ int item=0; int[] numArray=new int[100]; count=0;       while (item !=8){ menu(); item = kb.nextInt();...
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;...
Complete the // TODO sections in the EasyRental class. Create a method that implements an iterative...
Complete the // TODO sections in the EasyRental class. Create a method that implements an iterative sort that sorts the vehicle rentals by color in ascending order (smallest to largest) Create a method to binary search for a vehicle based on a color, that should return the index where the vehicle was found or -1 You are comparing Strings in an object not integers. Ex. If the input is: brown red white blue black -1 the output is: Enter the...
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...
import java.util.Scanner; public class ListDriver {    /*    * main    *    * An...
import java.util.Scanner; public class ListDriver {    /*    * main    *    * An array based list is populated with data that is stored    * in a string array. User input is retrieved from that std in.    * A text based menu is displayed that contains a number of options.    * The user is prompted to choose one of the available options:    * (1) Build List, (2) Add item, (3) Remove item, (4) Remove...
You must alter the Queue class you created in L5 to make it a CIRCULAR Queue...
You must alter the Queue class you created in L5 to make it a CIRCULAR Queue class . Call your class Queue. it must be a template class. public class Queue { } I have put a driver program in the module . It is called CircularQueue.java This driver program should then run with your Queue class (no modifications allowed to the driver program). Your Queue class should have at least the following methods: one or more constructors, enqueue, dequeue,...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT