#include<iostream> // selection sort code in c++ #include<iomanip> using namespace std; int main() { int i,j,k,n; cout<<"\nenter the no of integers : "; cin>>n; long signed int a[n],temp; cout<<"\nenter the integers : "; for(i=0;i<n;i++) { cin>>a[i]; } cout<<"\narray before sorting : "; for(i=0;i<n;i++) { cout<<a[i]<<" "; } for(i=0;i<(n-1);i++) { for(j=i+1;j<n;j++) { if(a[i]>a[j]) { temp=a[i]; a[i]=a[j]; a[j]= temp; } } } cout<< "\narray after sorting :"; for(i=0;i<n;i++) { cout<< a[i]<< " "; } return 0; }
Labels
Popular Posts
-
Binary Tree: A Tree in which each node has a degree of atmost 2. i.e. it can have either 0,1 or 2 children. Here, leaves a...
-
Recurrence relation : A recurrence relation is an equation that defines a sequence based on a rule that gives the next term as a funct...
-
BUBBLE SORT : Bubble sort is a simple sorting algorithm ...
Blog Archive
- March 2017 (1)
- March 2016 (1)
- October 2015 (1)
- September 2015 (1)
- August 2015 (5)
- July 2015 (2)
- June 2015 (4)
- January 2015 (4)
- December 2014 (5)
- November 2014 (1)
- October 2014 (1)
- September 2014 (3)
Powered by Blogger.