Advertisement
Guest User

Untitled

a guest
Aug 17th, 2019
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.60 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. void add_element(int *arr, int n, int currpos, int newel)
  4. {
  5. if(currpos == n) arr[currpos] = newel;
  6. else {
  7. if(newel >= arr[currpos])
  8. {
  9. int k = arr[currpos];
  10. arr[currpos] = newel;
  11. return add_element(arr, n, currpos + 1, k);
  12.  
  13. }
  14. return add_element(arr, n, currpos + 1, newel);}
  15. }
  16.  
  17. int main()
  18. {
  19.  
  20. int *arr = (int *)malloc(sizeof(int) * 16);
  21. arr[0] = 9;
  22. arr[1] = 7;
  23. arr[2] = 6;
  24. arr[3] = 5;
  25. arr[4] = 2;
  26. arr[5] = 1;
  27. add_element(arr, 7, 0, 3);
  28. for(int i = 0; i < 7; i++)
  29. {
  30. printf("%d\n", arr[i]);
  31. }
  32. free(arr);
  33. return 0;
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement