EBK BIG JAVA: EARLY OBJECTS, INTERACTIV
EBK BIG JAVA: EARLY OBJECTS, INTERACTIV
6th Edition
ISBN: 8220102010314
Author: Horstmann
Publisher: YUZU
Question
Book Icon
Chapter 18, Problem 7PE
Program Plan Intro

Merge Sort

Program plan:

Filename: “MergeSorter.java”

This code snippet creates a class “MergeSorter”. In the code,

  • Define a class “MergeSorter”.
    • Declare an array “a”.
    • Declare an array list “l”.
    • Define the constructor “MergeSorter ()”.
      • Set the array “a” equal to “anArray”.
      • Define “l”.
      • Iterate a “for” loop.
        • Set elements of “a” to “l”.
    • Define the constructor “MergeSorter ()”.
      • Set the array “l” equal to “aList”.
    • Define the method “sort()”.
      • If the size of “l” is less than or equal to 1,
        • Return.
      • Create two array lists “first” and “second”.
      • Iterate a “for” loop,
        • Add elements of “l” to “first”.
      • Iterate a “for” loop,
        • Add elements of “l” to “second”.
      • Create generic array “firstSorter”.
      • Create generic array “secondSorter”.
      • Call the method “sort()” on “firstSorter”.
      • Call the method “sort()” on “secondSorter”.
      • Call the method “merge()”.
      • If “a” is not empty,
        • Iterate a “for” loop,
          • Set elements of “l” to “a”.
    • Define the method “merge()”.
      • Declare integer “iFirst”.
      • Declare the variable “iSecond”.
      • Declare a variable “j”.
      • Iterate a “while” loop for merging.
        • if “iFirst” is less than “iSecond”.
          • Set “iFirst” to “l”.
          • Increment “iFirst” by 1.
            • Else,
              • Set “iSecond” to “l”.
              • Increment “iSecond” by 1.
            • Increment “j” by 1.
      • Iterate a “for” loop.
        • Set the first half values of “l”.
      • Iterate a “for” loop.
        • Set the second half values of “l”.

Filename: “MergeSortTester.java”

This code snippet creates a class “MergeSortTester”. In the code,

  • Define a class “MergeSortTester”.
    • Define the “main” method.
    • Define the string array “words[]”.
    • Define the object of “MergeSorter”.
    • Call “sort()”.
    • Print the values in the array “words[]”.
    • Print the expected value.

Blurred answer
Students have asked these similar questions
Complete the JavaScript function addPixels () to calculate the sum of pixelAmount and the given element's cssProperty value, and return the new "px" value. Ex: If helloElem's width is 150px, then calling addPixels (hello Elem, "width", 50) should return 150px + 50px = "200px". SHOW EXPECTED HTML JavaScript 1 function addPixels (element, cssProperty, pixelAmount) { 2 3 /* Your solution goes here *1 4 } 5 6 const helloElem = document.querySelector("# helloMessage"); 7 const newVal = addPixels (helloElem, "width", 50); 8 helloElem.style.setProperty("width", newVal); [
Solve in MATLAB
Hello please look at the attached picture. I need an detailed explanation of the architecture
Knowledge Booster
Background pattern image
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education