Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- %% Implement your solution for the sorting function in here: %%
- % --------------- Do Not Edit This!!! ---------------
- function [arr] = max_sort(arr)
- % Setup
- n = length(arr);
- % --------------- Edit From Here ---------------
- % #################################################
- new_arr = zeros(1,n);
- highest_num = arr(1);
- count = 1;
- flag = false;
- for i=1:n
- num = arr(i);
- if (num >= highest_num)
- if (flag)
- new_arr(count) = new_arr(end);
- count = count + 1;
- end
- new_arr(end) = num;
- highest_num = num;
- flag = true;
- else
- new_arr(count) = num;
- count = count + 1;
- end
- end
- arr = new_arr;
- % #################################################
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement