I am trying to run Bubble Sort Technique using pointers and dynamic memory allocation, but the code doesn't seem to run (eclipse crashes). Please help. I am posting the code below:
#include<iostream>
using namespace std;
void sort(int *);
//===========================================
int main()
{
int *a = new int[5];
int *c = a;
cout << "Enter the numbers\n";
for(int i = 0; i < 5; i++)
{
cin >> *a;
a++;
}
a = a - 4;
sort(a);
cout << c;
cout<<"\nSorting complete";
cout<<"\n Array after sorting";
for(int i = 0; i < 5; i++)
{
cout << *c << endl;
c++;
}
delete []a;
delete []c;
a = c = NULL;
return 0;
}
//===========================================
void sort(int *a)
{
int *b = a + 1;
for(int i = 0; i < 5; i++)
{
if(*a > *b)
{
int temp = *a;
*a = *b;
*b = temp;
a++;
b++;
}
else
{
b++;
continue;
}
}
}
Thank you in advance.