Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

My code is below, but I cannot use the last line of code(less=string(worda) function sortedarray=sortWords(array) sortedarray={}; while ~isempty(array) [m,pos]=findSmallest(array); array(pos)=[]; sortedarray=[sortedarray m]; end end function

image text in transcribedMy code is below, but I cannot use the last line of code(less=string(worda)

function sortedarray=sortWords(array)

sortedarray={};

while ~isempty(array)

[m,pos]=findSmallest(array);

array(pos)=[];

sortedarray=[sortedarray m];

end

end

function [m, pos]=findSmallest(array)

m = array{1};

pos=1;

for i=2:length(array)

if isLessWord(array{i}, m)

m=array{i};

pos=i;

end

end

end

function less=isLessWord(wordA,wordB)

worda=lower(wordA);

wordb=lower(wordB);

less=string(worda)

end

Write a function sortWords (array) that does the following: 1. Takes as an input a cell array of strings consisting of letters only. (1 pts) 2. Returns a cell array with all the strings in alphabetical order. (5 pts) 3. The function should ignore whether letters are lower case or upper case. (2 pts) Test your function with the following: (e pts) >> sorted-sortWords ({"Hello, , , hell, , , abc, , , aa, , , a za , , , aab, , , AaBb , , , a, }) sorted- 'a' 'aa''aab' 'AaBb' 'abc' 'aza''hell' 'Hello Note: Your function may not contain any built-in MATLAB function(s) that deal with sorting or finding minimum values. If your function-does use these built-in functions, up to 8 points may be deducted from your total. Hint: Use the program sharkSort (vec) as a starting point and amend it so that it works for this programming assignment. For example your function could start as follows (fill in the blanks as necessary)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Programming Languages 12th International Symposium Dbpl 2009 Lyon France August 2009 Proceedings Lncs 5708

Authors: Philippa Gardner ,Floris Geerts

2009th Edition

3642037925, 978-3642037924

More Books

Students also viewed these Databases questions