heap corruption/ radix help

i keep getting a heap corruption after it runs , also im quite confused where the radix code went wrong also

[code]
#include
#include
#include
using namespace std;

void print (int array[], int size)
{
for (int i=0;iarray[i+1])
{
hold = array[i];
array[i]=array[i+1];
array[i+1]=hold;

}
}
}
}
void selection(int array[],int size)
{
int pivot, hold;

for(int i = 0; iarray[i])&&(leftarray[larger])&&(right= 0;i--)
{
heapify(array,i,size);
print(array,size);
cout<<"
";
}
}
void heapSort(int array[],int size)
{
buildHeap(array,size);
for (int i = size;i > 0;i--)
{
int hold = array[0];
array[0]=array[size-1];
array[size+1]=hold;
size = size - 1;
heapify(array,0,size);
}

}
/*
void radixsort_exchange( int array[], int size)
{
radix(array, 0, size-1, );
}
void radix(int array[ ], int left, int right, int position )
{
int hold ;
int a, b;

if(( right > left ) && ( position >= 0))
{
a = left;
b = right;
do
{
while(((( array[ a ] >> position ) & 1 ) == 1) && ( a < b ))
a++;

while((((array[ b ] >> position ) & 1 ) == 0) && ( a < b ))
b--;

hold = array[a];
array[a] = array[a];
array[b] = hold;
} while (b!= a);

if((( array[right] >> position ) & 1 ) == 0 )
b++;

radix( array, left, b - 1, position - 1);
radix( array, b, right, position - 1);

}
}*/

[/code]
[code]
#include
#include
#include"header.h"
using namespace std;


int main ()
{
int size;
cout<<"Enter a Size for the array"<<endl;
cin>>size;
int *array=NULL;
array= new int [size];

cout<<"Original array:";
newArray(array,size);
print(array,size);
cout<<"
";
cout<<"Bubble:";
bubble(array,size);
print(array,size);
cout<<"
";
cout<<"Original array:";
newArray(array,size);
print(array,size);
cout<<"
";
cout<<"Selection:";
selection(array,size);
print(array,size);
cout<<"
";
cout<<"Heap:";
newArray(array,size);
heapSort(array,size);

system ("pause");

delete [] array;
return 0;
}
[/code]
[code]
#ifndef SORTS_H
#define SORTS_H

void print(int [], int);
void newArray(int[], int);
void bubble(int [], int);
void selection(int [], int);
int parent (int);
int leftChild(int);
int rightChild(int);
void heapify(int[],int,int);
void heapSort(int[],int);
void buildHeap(int[],int);
void radix(int,int,unsigned int,int[],int);

#endif
[/code]
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories