QuestionQuestion

Write a method void interchange (List<E> l) which interchanges the current element in the list and the one following it. (First make it work in the normal case; then, if make sure it handles special cases, such as: the list is empty; the list has only one element; current is at the end of the list)

Write a method void reverse (List<E> l) which reversed the order of items stored in the list. Again, make sure it works for any special cases you can think of.

Write a method List mergeLists (List<E> l1, List<E> l2)which takes two sorted Lists as input, producing a new List containing all the elements of both lists, also sorted. The new list is the return value for the method.

Solution PreviewSolution Preview

This material may consist of step-by-step explanations on how to solve a problem or examples of proper writing, including the use of citations, references, bibliographies, and formatting. This material is made available for the sole purpose of studying and learning - misuse is strictly forbidden.

/** Array-based list implementation */
class AList<E> implements List<E> {
private static final int defaultSize = 10; // Default size
private int maxSize;       // Maximum size of list
private int listSize;       // Current # of list items
private int curr;          // Position of current element
private E[] listArray;      // Array holding list elements

/** Constructors */
/** Create a list with the default capacity. */
AList() { this(defaultSize); }
/** Create a new list object.
      @param size Max # of elements list can contain. */
@SuppressWarnings("unchecked") // Generic array allocation
AList(int size) {
    maxSize = size;
    listSize = curr = 0;
    listArray = (E[])new Object[size]; // Create listArray
}

public void clear()         // Reinitialize the list
    { listSize = curr = 0; } // Simply reinitialize values

/** Insert "it" at current position */
public void insert(E it) {
    assert listSize < maxSize : "List capacity exceeded";
    for (int i=listSize; i>curr; i--) // Shift elements up
      listArray[i] = listArray[i-1]; //   to make room
    listArray[curr] = it;
    listSize++;               // Increment list size
}...
$20.00 for this solution

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available Java Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Decision:
Upload a file
Continue without uploading

SUBMIT YOUR HOMEWORK
We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats