Saturday, April 9, 2016

C++ - Bubble Sort Using Pointer

"Jai Saraswati Maa"

Hi ... Dear All ..Today I am uploading a superb example of Bubble Sort using pointer.
In this example we define our own  function to sort the Array.
Special Thanks to Aditya Abhishek (Student)

Please check.
Please Use CodeBlock

A. Code is  **************  



using namespace std;
void bubble(int *ptr,int s)
{
inti,j;
int temp;
for(i=0;i<s;i++)
    {
for(j=0;j<s-i;j++)
        {
if(*(ptr+j)>*(ptr+j+1))
            {
                  temp=*(ptr+j);
                *(ptr+j)=*(ptr+j+1);
                *(ptr+j+1)=temp;
            }
-
        }
    }
}

int main()
{
intarr[10];
inti;
int size;
cout<<"Enter Size OF An Array : ";
cin>>size;
cout<<"Enter The Element OF Array :";
for(i=0;i<size;i++)
cin>>arr[i];
cout<<"Before Sorting :"<<endl;
for(i=0;i<size;i++)
cout<<" "<<arr[i];
bubble(arr,size);
cout<<"After Sorting :";
for(i=0;i<size;i++)
cout<<" "<<arr[i];
return 0;

}

No comments:

Post a Comment