• Home
  • Blog
  • CS 20A SMC Solution Class to Implement a Heap Using Java ArrayList Exercise

CS 20A SMC Solution Class to Implement a Heap Using Java ArrayList Exercise

0 comments

Write a solution class to implement a heap using Java’s ArrayList (Links to an external site.). This is a max heap, which means the highest priority element is stored at the root level in a complete or full binary tree. Natural order is used in ranking the priority of the elements in the heap, namely, 6 has higher priority than 5, which has higher priority than 2, so on and so forth.

You are responsible for implementing the following solution methods:

  • void enqueue(int element): this method enqueues an integer element into heap.
  • void dequeue(): this method dequeues the highest priority element from heap.
  • void reheapUp(int element): this method is called by enqueue(element); it either iteratively or recursively shifts the element up the tree to “reheap” it.
  • void reheapDown(int element): this method is called by dequeue(); it either iteratively or recursively shifts the element down the tree to “reheap” it.

Your Java implementation may start with the following template.

About the Author

Follow me


{"email":"Email address invalid","url":"Website address invalid","required":"Required field missing"}