Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int i;
- int a[10];
- int insertionsort()
- {
- for (i=1;i<10;i++)
- {
- int j=i+1;
- while (j>1)
- {
- if (a[j]<a[j-1])
- {
- int tmp = a[j-1];
- a[j-1] = a[j];
- a[j] = tmp;
- j=i-1;
- }
- }
- }
- }
- int main()
- {
- cout << "enter numbers between 1 to 10 in any order:" <<endl;
- for (i=1;i<11;i++)
- {
- cin >> a[i];
- }
- insertionsort();
- cout << "sorted:" << endl;
- for (i=1;i<11;i++)
- {
- cout << a[i] << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement