#include<iostream> #include<iomanip> using namespace std; int main() { int i,j,k,n,m; cout<<"\nenter the no of integers : "; cin>>n; double a[n],temp; // for any real numbers cout<<"\nenter the integers : "; for(i=0;i<n;i++) { cin>>a[i]; } cout<<"\n\narray before sorting : "; for(i=0;i<n;i++) { cout<<a[i]<<" "; } cout<<"\n"; for(i=1;i<n;i++) { for(j=0;j<i;j++) { if(a[j]>a[i]) { temp=a[j]; a[j]=a[i]; for(k=i;k>j;k--) // shifting of elements { a[k]=a[k-1]; } a[k+1]=temp; } } } cout<<"\n\nafter sorting the array : "; for(i=0;i<n;i++) { cout<<a[i]<<" "; } cout<<"\n"; 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...
-
BUBBLE SORT : Bubble sort is a simple sorting algorithm ...
-
Keywords – II Enum : An enum type is a special data type that enables for a variable to be a set of predefined co...
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.