MS Rumi. Powered by Blogger.
Showing posts with label Bubble Sort With Example. Show all posts
Showing posts with label Bubble Sort With Example. Show all posts

Sunday, 19 October 2014

Bubble Sort With Pointer

Bubble Sort With Pointer In Data Structure

C++ Coding In Microsoft Visual 6

#include<iostream.h>
void bubleSort (int *arr);
//Main Function
void main ()
{
    int arr[5];
    cout<<"Enter Numbers To Store In Array"<<endl;
    for(int i=0; i<5; i++)
    {
        cin>>arr[i];
    }
   
   
    cout<<"Beofre Sorting"<<endl;
    for(i=0; i<5; i++)
    {
        cout<<arr[i]<<",";
    }

    //sorting array
    bubleSort(arr);
   
    cout<<"After Sorting"<<endl;
    for(i=0; i<5; i++)
    {
        cout<<arr[i]<<",";
    }

}

// Sorting Function
void bubleSort (int *arr)
{
    for(int i=0; i<4; i++)
        {
            for(int j=0; j<4; j++)
            {
                if(arr[j]>arr[j+1])
                {
                    arr[j]=arr[j]+arr[j+1];
                    arr[j+1]=arr[j]-arr[j+1];
                    arr[j]=arr[j]-arr[j+1];
                }
            }
        }
}

E-mail Newsletter

Sign up now to receive breaking news and to hear what's new with us.

Recent Articles

TOP