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
Discuss how business intelligence and data visualization work together to help decision-makers and data users. Provide 2 specific use cases.
This week we will be building a regression model conceptually for our discussion assignment. Consider your current workplace (or previous/future workplace if not currently working) and answer the following set of questions. Expand where needed to help others understand your thinking:  What is the most important factor (variable) that needs to be predicted accurately at work? Why? Justify its selection as your dependent variable.
According to best practices, you should always make a copy of a config file and add a date to filename before editing? Explain why this should be done and what could be the pitfalls of not doing it.
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