MS Rumi. Powered by Blogger.

Sunday 19 October 2014

Bubble Sort With Pointer

By Unknown  |  09:09 No comments

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];
                }
            }
        }
}

Author: Unknown

Hello, I am Author, thanks for visiting my blog. Bookmark this....

0 comments:

E-mail Newsletter

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

Recent Articles

TOP