Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- int main()
- {
- int arr[100],s,t,i,j;
- cout<<"Enter the size of the array: ";
- cin>>s;
- cout<<"\n\nEnter elements of the array: ";
- for(i=0; i<s; i++)
- {
- cin>>arr[i];
- }
- cout<<"\n\nElements of the array before sorting: ";
- for(i=0; i<s; i++)
- {
- cout<<arr[i]<<" ";
- }
- for(i=0; i<s-1; i++)
- {
- for(j=i+1; j<s; j++)
- {
- if(arr[i]>arr[j])
- {
- swap(arr[i],arr[j]);
- }
- }
- }
- cout<<"\n\nElements of the array after insertion sort: ";
- for(i=0; i<s; i++)
- {
- cout<<arr[i]<<" ";
- }
- cout<<"\n\n";
- }
Advertisement
Add Comment
Please, Sign In to add comment