Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

can you please help me fix this error SortedList.java code: package DSA; public class SortedList { private static int MAX = 10; private int size;

can you please help me fix this error

image text in transcribed

SortedList.java code:

package DSA; public class SortedList { private static int MAX = 10; private int size; private E info[];

public int size() { return size; }

public boolean isFull() { return size == MAX; }

public boolean isEmpty() { return size == 0; }

public SortedList() { this(MAX); }

public SortedList(int capacity) { MAX = capacity; info = ((E[]) new Object[capacity]); }

public void addItem(E item) { // change this code to make sure that the size does not exceeds MAX // print a message (check output) in case size of MAX is exceeded if(isFull()){ //checks if the list is full System.out.println("List is full with "+size+" items: "+toString()); //print the statements with list values }else{ int i; for (i = 0; i (Integer) info[i]) continue; else break; } for (int index = size; index > i; index--) info[index] = info[index - 1]; info[i] = item; size++; }}

public boolean getItem(E item) { // Change this method to print visited numbers info[i] and to stop if // info[i]>item String s=" "; for (int i = 0; i

public boolean getItemBSA(E item) { // Change this method to print visited numbers info[mid] String s=" "; int mid; int first = 0; int last = size - 1; boolean moreToSearch = (first (Integer) info[mid]) { first = mid + 1; moreToSearch = (first

public boolean deleteItem(E item) { for (int i = 0; i

public String toString() { // implement this method String s=" "; for(int i=0;i

public void mergeLists(SortedList sl) { // implement this method using class method addItem for(int i=0; i

Task1 SortedList Driver code:

class Task1 { public static void main(String[] args) { SortedList list1= new SortedList(); //declare 1st sorted list object SortedList list2= new SortedList(); //declare 2nd sorted list object int items [] = {38,18,9,15,8,5}; for(int i:items){ //initialize list1 list1.addItem(i); System.out.println("list is "+list1.size()+" items: "+list1); //print list list1.addItem(31);//add item 31 to the list System.out.println("List after inserting 31 is "+list1.size()+" items: "+list1.toString()); //print list items list1.getItem(8); // get item 8 list1.getItem(17); // get item 17 int [] array = {33,12,22,6,10}; for(int a:array){ list2.addItem(a); //add items to list 2 } System.out.println("List2 after adding 33, 12, 22, 6 and 10 is "+list2.size()+" items"+list2.toString() ); // print list1.getItemBSA(19); //Retrieve item 19 from the list list1.deleteItem(38);//Delete item 38 from the list System.out.println("List after deleting 38 is "+list1.size()+" items: "+list1.toString()); list1.mergeLists(list2); //Merge the second list into the first one } } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

Be familiar with the integrative servicescape model.

Answered: 1 week ago

Question

Determine the roles of spatial layout and functionality.

Answered: 1 week ago