Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- void input(int &n, int the_array[]);
- void output(int n, int the_array[]);
- void sorting(int n, int the_array[]);
- main()
- {
- int n;
- int arr[n];
- input(n, arr);
- cout << "Before sorting : " << endl;
- output(n, arr);
- cout << endl;
- cout << "After sorting : " << endl;
- sorting(n, arr);
- }
- void input(int &n, int the_array[])
- {
- cout << "input n : ";
- cin >> n;
- the_array[n];
- for(int i = 0; i < n; i++)
- {
- cout << "[" << i+1 << "] = ";
- cin >> the_array[i];
- }
- }
- void output(int n, int the_array[])
- {
- for(int i = 0; i < n; i++)
- {
- cout << the_array[i] << " ";
- }
- }
- void sorting(int n, int the_array[])
- {
- for(int i = 0; i < n; i++)
- {
- int j = i;
- while((j > 0) && (the_array[j] < the_array[j-1]))
- {
- int temp = the_array[j];
- the_array[j] = the_array[j-1];
- the_array[j-1] = temp;
- j = j - 1;
- }
- }
- output(n, the_array);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement