Question: // Array implementation of sorted list: xxxxxH3.java import java.util.*; import java.io.*; public class xxxxxH3{ // class Variables private int n, count = 0; String arr[];

// Array implementation of sorted list: xxxxxH3.java

import java.util.*; import java.io.*; public class xxxxxH3{

// class Variables private int n, count = 0; String arr[];

//use a short word for prt to save typing PrintStream prt = System.out;

//insert x in a sorted list if list is not full public int insertsorted(String x){

int p, j; prt.printf(" \t\tInsert %s in a sorted list:", x);

if (count == n) return 0;//list is full // complete the rest return 1;

} // end insertsorted

//sequential serach for x in a sorted list // if successful return position of x in the // sorted list otherwise return

public int searchsorted(String x){ prt.printf(" \t\tSearch for %s in a sorted list:", x);

if (count == 0) return -1; //list is empty // complete the rest return -1;

} // end searchsorted

//delete x from a sorted list public int deletesorted(String x){

prt.printf(" \t\tDelete %s from a sorted list:", x); if (count == 0) return 0;//list is empty int i, p = searchsorted(x);

if (p == -1) return 0; //x is not found

//Shift to left array from position p for (i = p ; i < count-1 ; i++)

arr[i] = arr[i+1]; // end for count--; return 1; //successful deletion

} // end delete

// print list elements formatted public void printlist(){

int i; prt.print(" \tList contents: ");

for (i = 0; i < count; i++) prt.printf("%s, ", arr[i]);

// enf for } // end printlist

// insert, delete and search in the list private void process(){

int j, m, k, p, s; String x; prt.print("\tArray implementation of sorted list. This program first reads:n array

" \tNo. of elements to insert, followed by elements to insert," + " \tNo. of elements to search, followed by elements to search," + " \tNo. of elements to delete, followed by elements to delete" + " \t\tTo compile: javac xxxxxH3.java" +

" \t\tTo execute: java xxxxxH3 < any data file"); // open input file Scanner inf = new Scanner(System.in); try{

//read array size n = inf.nextInt(); //read no. of elements to insert m = inf.nextInt();

// Allocate Space for array arr = new String[n];// prt.printf(" \tCreating array of size %4d:",n);

prt.printf(" \tInsert %2d elements in the sorted list.", m); for(j = 1; j <= m; j++){

x = inf.next();//read x to insert s = insertsorted(x); //insert x if (s == 1)

prt.printf(" Successful insertion."); else

prt.printf(" Failed insertion."); // end for

} printlist();//print linked list elements

//read no. of elements to search in list m = inf.nextInt(); prt.printf(" \tSearch for %d elements in sorted list.", m); for(j = 1; j <= m; j++){

x = inf.next(); // read x to serach s = searchsorted(x); //delete x if (s >= 0)

prt.printf(" found at position %d", s); else

prt.printf(" not found.");

}// end for

//read no. of positions to delete from list m = inf.nextInt(); prt.printf(" \tDelete %d elements from sorted list.", m); for(j = 1; j <= m; j++){

x = inf.next(); // read x to delete s = deletesorted(x);//delete x if (s == 1)

prt.printf(" Successful deletion"); else

prt.printf(" Failed deletion."); }// end for printlist();//print list elements

// close input file inf.close();

} catch (Exception e){ prt.print(" Exception " + e + " ");}

} // end process

// main method public static void main(String args[]) throws Exception{

xxxxxH3 lst = new xxxxxH3(); lst.process();

//MAKE SURE TO WRITE YOUR NAME IN NEXT LINE System.out.printf(" \tAuthor: Gh. Dastghaibyfard Date: " + java.time.LocalDate.now());

} // end main } // end class xxxxxH3

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!