Question: Implement the SortedIntList class shown on the following slides. The class implements a list of ints that are maintained in both ascending and descending order.

Implement the SortedIntList class shown on the following slides. The class implements a list of ints that are maintained in both ascending and descending order. For each int in the list, there must only be one node. You can add private methods and instance variables as needed. Write code to test the program as well.

Code Skeleton:

__________________________________________________________________________

import java.io.*; import java.util.*;

public class SortedIntList { //Implements a list of ints //the ints can be accessed in ascending or descending order //there is only 1 node for each int private class Node { private int data; private Node next[]; // next[0] is the next reference for ascending order // next[1] is the next reference for descending order private Node(int d, Node aN, Node dN) { data = d; next = new Node[2]; next[0] = aN; next[1] = dN; } }

private Node heads[]; // heads[0] is the head of the ascending order list //heads[1] is the head of the descending order list

public SortedIntList() { heads = new Node[2]; }

public void insert(int d) { //insert d into the list maintaining the ascending and descending orders }

public void remove(int d) { //remove all occurrences of d from the list maintaining the ascending and descending orders }

public void ascPrint() { // print a comma delimited list of the ints in ascending order }

public void descPrint() { // print a comma delimited list of the ints in descending order }

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!