Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- %% Implement your solution for the sorting function in here: %%
- function [sorted_arr] = linear_sort(arr)
- positive_arr = arr(arr > 0);
- negative_arr = -arr(arr < 0);
- positive_hist_arr = zeros(1,max(positive_arr));
- positive_hist_arr(positive_arr) = positive_arr;
- negative_hist_arr = zeros(1, max(negative_arr));
- negative_hist_arr(negative_arr) = negative_arr;
- correct_negative_arr = find(negative_hist_arr > 0);
- correct_negative_arr = -correct_negative_arr(end:-1:1);
- if (sum(arr == 0))
- sorted_arr = [correct_negative_arr, 0, find(positive_hist_arr >0)];
- else
- sorted_arr = [correct_negative_arr, find(positive_hist_arr >0)];
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement