Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

(Java) Implement the basic functions of the sorted singly linked list below. All elements should be sorted in increasing order and should not have repeating

(Java) Implement the basic functions of the sorted singly linked list below. All elements should be sorted in increasing order and should not have repeating elements. Implement the insert, getAllElement, merge_naive function( merges another sorted list into the current one by going through its element one by one and call the insert function). The merge_smart function merges another sorted list into the current one using the smart merging strategy. An image of the SLLMainClass is below.

// implementing SortedSLLClass {

// constructor

public SortedSLLCass() {

// fill in

}

// copy constructor: copy the contents of other SSLL into this one.

public SortedSLLClass(SortedSLLClass otherSSLL) {

// fill in

}

// insert an integer value into the list

public boolean insert(int val) {

// fill in

return false;

}

// merge otherSSLL into the cuurent list (naive)

// read and insert elements from other SSLL one-by one into this list

public void merge_naive (SortedSLLClass other SSLL) {

// fill in

}

// merge other SSLL into the current list (smart)

// use two synchronized pointers to merge

// it is easier if you start a new list of nodes

// after merging, you can use this list of nodes to replace the content of the current one

public void merge_smart (SortedSLLClass other SSLL) {

// fill in

}

// get all elements of the list, store them in an array.

public int [] getAllElements() {

// fill in

image text in transcribed

import iava.util. Scanner: inport java.io.File: long startine, endTine, totalTime: String tnamRs startTime SatsnsurrsntnMAlis SortedSLLClass[1 sslllistnew SortedSLLClass[n; public class SLLMainclass public static SortedSLLClass ParseArray(String file name) Scanner s null; int tnRA; SortedSLLClass myssLL = new SortedSLLClass(); try Inane - args[) ysten.out println Input "+i+": " 511 1s ParseArray foane read one ist new scanner ( new File(file-name)); while (as hasNext)) // if invalid input file, print NULL and exit ysten.ut.riato("NULL"; Systen.out println("Error parsing file: "+fnane rcturn tysall.insent topi): System.out.print (tnei + "": return YSs1L catch (Exception e) totalTimeendTine- startTime: Systeutotn("List constructing tine: totalTine return null; public static void main(String args) naive implenentation startTime-Staten.surrensTAneMLLI (); SortedS LLClass nerged-na ive- new SortedSLLClass(LLList.10] ; // copy the intn-args.length; nunber of lists to read return; t list into nerged_naive ++i) merged-naive.nerge-na ive(1LIA for(int i = 1; i n; long startTime, endTine, totalTime; !i)); String tnan: startTine Syatenurrnt TinsMillia SortedSLLClass(]11.at. = new SortedSLLClass [n]; totalTire endTime - startTime SystusRriatn"Naive merging result: ): / output the final result int I naive_result nerged_naive.getAllElenents) for int i-e; i naive_result.length; i++) for(int i-e; i<>

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

Big Data Fundamentals Concepts, Drivers & Techniques

Authors: Thomas Erl, Wajid Khattak, Paul Buhler

1st Edition

0134291204, 9780134291208

More Books

Students also viewed these Databases questions

Question

Define Management by exception

Answered: 1 week ago

Question

Explain the importance of staffing in business organisations

Answered: 1 week ago

Question

What are the types of forms of communication ?

Answered: 1 week ago

Question

Explain the process of MBO

Answered: 1 week ago