Problem - 2
Write a C++ program to sort an array (bubble sort), using the concept of pointers.
Solution
:
#include <iostream>
using namespace std;
void bubble(int*,int);
int main()
{
int array[5],size=5,*point;
for(int num=0; num < size; num++)
{
cout << "Enter integer " << num+1 << " : ";
cin>>array[num];
}
point=array;
bubble(point,size);
}
void bubble(int *point,int size)
{
int co1,co2,swap;
for(co1=0;co1<size-1;co1++)
{
for(co2=0;co2<size-co1-1;co2++)
{
if(*(point+co2)>*(point+co2+1))
{
swap=*(point+co2)
;
*(point+co2)=*(point+co2+1);
*(point+co2+1)=swap;
}
}
}
for(co1=0;co1<size;co1++)
{
cout<<*(point+co1)<<" , ";
}
};
6.8 Exercise Sets
●
Write a C++ program to sort an array (insertion sort), using the concept of pointers.
●
Write a function’s prototype statement, for a function named as “alpha”, that should return void type and should have a reference parameter to an integer “n”. Furthermore, it should have a pointer parameter to the allocated address of a long double “m”.