hello
I have an error in my cod which is trying to sort an arry using pointer i'd be grateful if any one help me to solve my problem and here is my code
[CODE=cpp]/*************** *************** *************** *************** *************** ******/
#include <list>
#include<iostre am>
#include <algorithm>
using namespace std;
//////////////////////////////////////////
double size(double* begin,double* end)
{
return ((end-begin)+1);
}
//////////////////////////////////////////
void swap_ptr(double * a, double* b) {
double temp = *a;
*a = *b;
*b = temp;
}
//////////////////////////////////////
void sort(double *begin, double *end)
{
for(int i=0;i<size(begi n,end);i++)
{
if(*(begin+i)>* (begin+i+1))
{
swap_ptr((begin +i),((begin+i+1 )));
}
}
}
///////////////////////
int main()
{
double* arr = new double[5];
for(int j=0;j<5;j++){
cin >> arr[j];
sort(arr,(arr)+ 4);
}
cout << "the Sorting array is " << arr << endl;
delete[] arr;
return 0;
}
/*************** *************** *************** *************** *************** ******/[/CODE]
I have an error in my cod which is trying to sort an arry using pointer i'd be grateful if any one help me to solve my problem and here is my code
[CODE=cpp]/*************** *************** *************** *************** *************** ******/
#include <list>
#include<iostre am>
#include <algorithm>
using namespace std;
//////////////////////////////////////////
double size(double* begin,double* end)
{
return ((end-begin)+1);
}
//////////////////////////////////////////
void swap_ptr(double * a, double* b) {
double temp = *a;
*a = *b;
*b = temp;
}
//////////////////////////////////////
void sort(double *begin, double *end)
{
for(int i=0;i<size(begi n,end);i++)
{
if(*(begin+i)>* (begin+i+1))
{
swap_ptr((begin +i),((begin+i+1 )));
}
}
}
///////////////////////
int main()
{
double* arr = new double[5];
for(int j=0;j<5;j++){
cin >> arr[j];
sort(arr,(arr)+ 4);
}
cout << "the Sorting array is " << arr << endl;
delete[] arr;
return 0;
}
/*************** *************** *************** *************** *************** ******/[/CODE]
Comment