Sort Array

#include <iostream>

using namespace std;

void sort(int a[], int N)

{

int i,j,k,t;

for (i=0;i<N-1;i++)

for (j=i+1;j<N;j++)

if (a[j]>a[i])

{t = a[j]; a[j]=a[i]; a[i] = t;}

}

main()

{

int i,N;

int x[]={1,6,8,5,4,3,6,7,4,0,8,15,22,77,8,22,35,21};

N = sizeof(x)/sizeof(int);

sort(x,N);

for (i=0;i<N;i++)

printf(“%d “,x[i]);

printf(“\n”);

system(“pause”);

return 0;

}

Or

void sort1(int a[], int N)

{

int i,j,k,t;

for (i=0;i<N;i++)

for (j=N-1;j>i;j–)

if (a[j]>a[j-1])

{t = a[j]; a[j]=a[j-1]; a[j-1] = t;}

}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: