Hey guys, I'm trying to create a iterative heapsort program and for some reason when I input 10 random numbers into the array, only 9 numbers are sorted. Here is an example of my input/output: Input: 45 15 2 44 30 83 30 86 66 49 // 10 random numbers Output: 2 15 30 30 44 49 66 83 86 // only 9 comes back sorted, the first index value before it was sorted is missing. In this case, 45 is missing. Here is my code: import java.util.Random; public class Heapsort { private static int indexOfMax(int []a, int i, int … |
+0 forum
2 | ||

Hello I am currently working on this code and the code can be runned well from 100-10,000 random elements after that the heap sort says stack over flow, im thinking the recursive calls are the cause of this, so please healp public static void MAX_HEAPIFY(int [] A, int i, int n) { int l = i + 1;//sets the left tree root int r = i + 2;//sets the right tree root int largest = 0; if(l <= n && A[l] > A[i]) { largest = l; } else { largest = i; } if(r <= n && A[r] > … |
+0 forum
3 | ||

Hello, This isn't the typical "I wrote a heap sort that doesn't work, help me please" thread, instead, I'm one step before that. I'd really like to [B]understand[/B] the innards of a heap sort before I attempt to write one. I'd like to give it a go from scratch, or from some basic pseudo code before resorting to dissecting an already written heap sort algorithm. Any information you could give to gently clear up the mystery here would be greatly appreciated. Regards, WigglesMcMuffin |
+0 forum
1 | ||

I'm trying to do an analysis of buildHeap vs. inserting an array of n values one at a time into a heap. I have a random case, best, and worst case. I was wondering if anyone knows what would actually be in an array to make the best and worst of a min heap? For example, with n values, what would be in my array to give the slowest possible time to both buildheap and the insert function when creating a heap? I understand the analysis but I just can't figure out what would give that worst case scenario. Thanks … |
+0 forum
1 | ||

Hey guys I've been asked to create an array of objects on the heap for my assignment but I cant seem to find any examples that explain it well enough on the web. So what I got is: [CODE]//Heabder File class Wheel{ public: Wheel() : pressure(32) { ptrSize = new int(30); } Wheel(int s, int p) : pressure(p) { ptrSize = new int(s); } ~Wheel() { delete ptrSize; } void pump(int amount) { pressure += amount; } private: int *ptrSize; int pressure; }; [/CODE] Ok so thats the wheel class and I have to coppy the objects into my "RacingCar" … |
+0 forum
5 | ||

i need to make a program that implements a heapsort using a binary tree. i understand the algorithm for how to do the sort, and i understand how it would be done using an array, but for my class i have to use a binary tree. The problem i am having is that nodes dont have a getParent, and although the finding a parents "index" in the tree is either n-1/2 or n-2/2, i dont understand how to get the index of the current node. for example in a binary tree that has 10 nodes, with the index at the … |
+0 forum
0 |

The End.