Advertisement
xotohop

qqqq

Jul 8th, 2020
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.70 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. template <class T2>
  6. void paste(T2 * array, int len, T2 elem)
  7. {
  8. for (int i = 0; i < len + 1; i++)
  9. if (array[i] >= elem)
  10. {
  11. for (int j = len + 1; j > i; j--)
  12. {
  13. int temp;
  14. array[j] = array[j - 1];
  15. array[j - 1] = array[j - 2];
  16. }
  17. array[i] = elem;
  18. break;
  19. }
  20. }
  21.  
  22. int main()
  23. {
  24. int arr1[11] = {10, 12, 23, 25, 26, 27, 28, 29, 30, 80};
  25. int p_elem1;
  26. cout << "enter int elem: "; cin >> p_elem1;
  27. cout << "int array before:" << endl;
  28. for (int i = 0; i < 10; i++)
  29. cout << arr1[i] << " ";
  30. cout << endl;
  31. paste(arr1, 10, p_elem1);
  32. cout << "int array after:" << endl;
  33. for (int i = 0; i < 11; i++)
  34. cout << arr1[i] << " ";
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement