Created
March 12, 2009 10:18
-
-
Save anshumanatri/78008 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<iostream.h> | |
#include<stdio.h> | |
#include<conio.h> | |
#include<stdlib.h> | |
#include<time.h> | |
int a[30000],n; | |
void selection_sort() | |
{ | |
int min,i,j; | |
for(i=0;i<n-1;i++) | |
{ | |
min=i; | |
for(j=i+1;j<n;j++) | |
if(a[j]<a[min]) | |
min=j; | |
int temp=a[i]; | |
a[i]=a[min]; | |
a[min]=temp; | |
} | |
} | |
void main() | |
{ | |
clrscr(); | |
int i; | |
clock_t t1,t2; | |
cout<<"\n Enter the number of elements:\t";cin>>n; | |
for(i=0;i<n;i++) { a[i]=random(n);} | |
t1=clock(); | |
selection_sort(); | |
t2=clock(); | |
cout<<"\n Sorted array:\n"; | |
for(i=0;i<n;i++) | |
cout<<a[i]<<" "; | |
cout<<"\n Time reqired by the selection sort algorithm:\t"<<(t2-t1)/CLK_TCK; | |
getch(); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment