Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- template <class T2>
- void paste(T2 * array, int len, T2 elem)
- {
- for (int i = 0; i < len + 1; i++)
- if (array[i] >= elem)
- {
- for (int j = len + 1; j > i; j--)
- {
- int temp;
- array[j] = array[j - 1];
- array[j - 1] = array[j - 2];
- }
- array[i] = elem;
- break;
- }
- }
- int main()
- {
- int arr1[11] = {10, 12, 23, 25, 26, 27, 28, 29, 30, 80};
- int p_elem1;
- cout << "enter int elem: "; cin >> p_elem1;
- cout << "int array before:" << endl;
- for (int i = 0; i < 10; i++)
- cout << arr1[i] << " ";
- cout << endl;
- paste(arr1, 10, p_elem1);
- cout << "int array after:" << endl;
- for (int i = 0; i < 11; i++)
- cout << arr1[i] << " ";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement