The world’s Largest Sharp Brain Virtual Experts Marketplace Just a click Away
Levels Tought:
Elementary,Middle School,High School,College,University,PHD
| Teaching Since: | Apr 2017 |
| Last Sign in: | 103 Weeks Ago, 3 Days Ago |
| Questions Answered: | 4870 |
| Tutorials Posted: | 4863 |
MBA IT, Mater in Science and Technology
Devry
Jul-1996 - Jul-2000
Professor
Devry University
Mar-2010 - Oct-2016
Need help. Can someone walk me through a program I have that is already written? Its a java program. I am suppose to build my implementation of  priority queue without the predefined java collection library. Need some one to walk me through a program I have. I need to ask questions like "What does this mean?" and"What if I write it this way?" I attached the program below. I will explain more in detail when I get a tutor.Â
Â
/** To change this license header, choose License Headers in Project Properties.* To change this template file, choose Tools | Templates* and open the template in the editor.*/import java.util.PriorityQueue;import java.util.Random;public class MyPriorityQueue {int arr[];int capacity;int count;public MyPriorityQueue(int capacity) {this.capacity = capacity;this.arr=new int[capacity];count=0;}//this method will insert a new integer into queuepublic void insert(int n){if(count==capacity){System.out.println("Queue is full");}else{arr[count]=Integer.MIN_VALUE;increaseKey(count,n);count++;}}void increaseKey(int i,int n){arr[i]=n;while(i>=0&&arr[i/2]<arr[i]){int temp=arr[i/2];arr[i/2]=arr[i];arr[i]=temp;i=i/2;}}void maxHeapify(int i){int left = 2 * i + 1;int right = 2 * i + 2;int largest = i;if( left < capacity && arr[ left ] > arr[ largest ] )largest = left;if( right < capacity && arr[ right ] > arr[ largest ] )largest = right;if( largest != i ){int temp = arr[ i ];arr[ i ] = arr[ largest ];arr[ largest ] = temp;