Advertisement
Guest User

max_Sort

a guest
Jan 22nd, 2019
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. %% Implement your solution for the sorting function in here: %%
  2. % --------------- Do Not Edit This!!! ---------------
  3. function [arr] = max_sort(arr)
  4.  
  5. % Setup
  6. n = length(arr);
  7.  
  8. % --------------- Edit From Here ---------------
  9.  
  10. % #################################################
  11. new_arr = zeros(1,n);
  12. highest_num = arr(1);
  13. count = 1;
  14. flag = false;
  15.  
  16. for i=1:n
  17. num = arr(i);
  18. if (num >= highest_num)
  19. if (flag)
  20. new_arr(count) = new_arr(end);
  21. count = count + 1;
  22. end
  23. new_arr(end) = num;
  24. highest_num = num;
  25. flag = true;
  26. else
  27. new_arr(count) = num;
  28. count = count + 1;
  29. end
  30. end
  31. arr = new_arr;
  32. % #################################################
  33.  
  34.  
  35. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement