Write a function sortWords (array) mat does Mu- following: Takes as an input a c
ID: 3936541 • Letter: W
Question
Write a function sortWords (array) mat does Mu- following: Takes as an input a cell array of .strings consisting of letters only. Returns a cell array with all the strings in alphabetical order. The function should ignore whether letters are lower case or upper case. Test your function with the following: >> sorted=sortWords({'Hello ', 'hell', ' abc', 'aa', 'aza', ' aab', 'AaBb', ' a'}) sorted = 'a' 'aa' 'aab' 'AaBb' 'abc' 'aza' 'hell' 'Hello' function sortedarray=sortWorda(array) sortedarray={}; while "isenpty(array) [m, pos]=findSmallest (array); array(pos)= []; sortedarray-laortodarray m]; end function [n.poa]"findSmallest(array) m =...; pos-1; for i=2:length(array) if isLessWord(..., ) m=....; pos= i; end end function less=isLessWord(vordA.vordB) worda=louer(vordA); wordb=lower(wordB);Explanation / Answer
a >= b if and only if:
i := first index such that a(i) ~= b(i);
if i exists, a(i) > b(i)
otherwise length(a)>=length(b)
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.