
explain this codes :
class Heap
{
int [] heapArray;
int maxSize, heapSize;
public Heap(int max)
{
maxSize=max;
heapSize=0;
heapArray = new int[maxSize];
}
public boolean insert(int ele)
{
if((heapSize+1) == maxSize)
return false;
heapArray[++heapSize]=ele;
int pos = heapSize;
while(pos != 1 && ele < heapArray[pos/2])
{
heapArray[pos] = heapArray[pos/2];
pos = pos/2;
}
heapArray[pos] = ele;
return true;
}
public void displayHeap()
{
System.out.println("The contents of heap are: ");
for(int i = 1;i <= heapSize;i++)
System.out.print(heapArray[i]+" ");
}
}
public class HeapTest {
public static void main(String args[]){
Heap h=new Heap(7);
h.insert(7);
h.insert(8);
h.insert(2);
h.insert(4);
h.insert(12);
h.insert(5);
h.displayHeap();
}
}

Trending nowThis is a popular solution!
Step by stepSolved in 4 steps with 5 images

- Python: Written without libraries method find_ansestors , that takes in an index i and returns all ancestors of node located at index i. What is the time complexity of your function? class ArrayBinaryTree: def __init__(self): self._heap = [] def find_ancestors(self, i: int): if(i==0): return;arrow_forwardTrace insertion sort for list ={18,57,8,89,7}arrow_forwardin java pls and thank you!arrow_forward
- Answer in 5 mins else downvotearrow_forwardpublic class HeapPriQ<T> implements PriQueueInterface<T>{ protected ArrayList<T> elements; // priority queue elements protected int lastIndex; // index of last element in priority queue protected int maxIndex; // index of last position in ArrayList protected Comparator<T> comp; public HeapPriQ(int maxSize) // Precondition: T implements Comparable { elements = new ArrayList<T>(maxSize); lastIndex = -1; maxIndex = maxSize - 1; comp = new Comparator<T>() { public int compare(T element1, T element2) { return ((Comparable)element1).compareTo(element2); } }; } public HeapPriQ(int maxSize, Comparator<T> comp) // Precondition: T implements Comparable { elements = new ArrayList<T>(maxSize); lastIndex = -1; maxIndex = maxSize - 1; this.comp = comp; } public boolean isEmpty() // Returns true if this priority queue is empty; otherwise, returns false. {…arrow_forwardComplete the code. The question is in the picture #include <iostream> using namespace std; class Queue { int size; int* queue; public: Queue() { size = 0; queue = new int[100]; } void add(int data) { queue[size] = data; size++; } void remove() { if (size == 0) { cout << "Queue is empty"<<endl; return; } else { for (int i = 0; i < size - 1; i++) { queue[i] = queue[i + 1]; } size--; } } void print() { if (size == 0) { cout << "Queue is empty"<<endl; return; } for (int i = 0; i < size; i++) { cout<<queue[i]<<" <- "; } cout << endl; } Queue operator+(Queue &obj) { Queue res; for(int i=0;i<this->size;i++) { res.add(this->queue[i]); } for(int i=0;i<obj.size;i++) { res.add(obj.queue[i]); } return res; } }; //your code goes here int main() { Queue q1; q1.add(42); q1.add(2); q1.add(8); q1.add(1); q1.print(); Queue2 q2; q2.add(3);…arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education





