// BubbleSort_Cplusplus.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream>
using namespace std;

void sort(int a[],int length)
        {
            int j=0;
            int i=0;
            if(length>0)
            {
           //The biggest one is at the end
            for (j =length-1; j > 0; j--)
            {
                for (i = 0; i < j; i++)
                {
                    if(a[i+1]<a[i])
                    {
                        a[i] ^= a[i + 1];
                        a[i + 1] ^= a[i];
                        a[i]^=a[i+1];
                    }
                }
            }
            }
            else
            {
                cout<<"Input a valid array."<<endl;
            }
        }

int _tmain(int argc, _TCHAR* argv[])
{
    int a[]={5,9,7,3,0};   
    int length =sizeof(a)/sizeof(int);
    cout<<length<<endl;
    sort(a,length);

    for(int i =0;i<length;i++)
    {
        cout<<a[i]<<endl;
    }
    cin.get();
    return 0;
}

posted on 2010-07-21 17:36  gracestoney  阅读(79)  评论(0编辑  收藏  举报