Introduction to Java Programming and Data Structures, Comprehensive Version (11th Edition)
Introduction to Java Programming and Data Structures, Comprehensive Version (11th Edition)
11th Edition
ISBN: 9780134670942
Author: Y. Daniel Liang
Publisher: PEARSON
Question
Book Icon
Chapter 23, Problem 23.7PE
Program Plan Intro

Min-heap

Program Plan:

Filename: Sorting.java

  • Import the required packages.
  • Create a class “Sorting”:
    • Define the main method
      • Generate the heap and initialize the heap elements.
      • Validate the size and the remove the elements from the heap.

Filename: MinHeap.java

  • Define the class “minHeap”
    • Create a new array list.
    • Create a method “MinHeap()”.
      • Define a method “MinHeap()”.
        • Loop that iterates to add all the elements into the heap.
      • Define a method “add()”
        • Add the objects into the list.
        • Assign the current index value.
        • Loop that validates the index value is greater than zero.
        • Based on the requirements and condition defined swap is made on the list.
        • Finally elements are added into the list
      • Define the method “remove()”
        • Validates the size of list.
        • Initialize the remove object.
        • Loop that iterates to validate the index value is greater the size of the list.
        • Based on the requirements and condition defined swap is made on the list.
        • Finally the required element is removed from the list.
      • Define the method “getsize()”
        • Used to return the size of the list.

Blurred answer
Students have asked these similar questions
Machine organization question The following operations are performed on a stack :PUSH A, PUSH B, POP, PUSH C, POP,POP,PUSH D, PUSH E, POP, PUSH F.What does the stack contain after each operation?
Can you explain how stack and heap works? With details on stack pointer, frame pointer etc
a.       What is the efficient method for “array resizing” implementation of the stack in “push” and “pop” cases? b.       The following is the postfix evaluation code for your reference. Explain the stack status for evaluating the following postfix expression                  3 4 5 + *
Knowledge Booster
Background pattern image
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning