Cody

# Problem 70. Alphabetize by last name

Solution 1893401

Submitted on 7 Aug 2019 by liu xinyang
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

### Test Suite

Test Status Code Input and Output
1   Pass

2   Pass
list = {'Harry Truman' 'Dwight Eisenhower' 'John F. Kennedy' 'Lyndon Johnson' 'Richard Nixon' 'Gerald Ford' 'Cleve Moler' 'Ronald Reagan' 'George Bush' 'Bill Clinton' 'George Bush' 'Barack Obama'}; alpha_list = {'George Bush' 'George Bush' 'Bill Clinton' 'Dwight Eisenhower' 'Gerald Ford' 'Lyndon Johnson' 'John F. Kennedy' 'Cleve Moler' 'Richard Nixon' 'Barack Obama' 'Ronald Reagan' 'Harry Truman'} assert(isequal(alphabetize(list),alpha_list))

alpha_list = 12×1 cell array {'George Bush' } {'George Bush' } {'Bill Clinton' } {'Dwight Eisenhower'} {'Gerald Ford' } {'Lyndon Johnson' } {'John F. Kennedy' } {'Cleve Moler' } {'Richard Nixon' } {'Barack Obama' } {'Ronald Reagan' } {'Harry Truman' } last_name = 0×0 empty cell array names = 1×2 cell array {'Harry'} {'Truman'} temp_name = 1×1 cell array {'Truman'} last_name = 1×1 cell array {'Truman'} names = 1×2 cell array {'Dwight'} {'Eisenhower'} temp_name = 1×1 cell array {'Eisenhower'} last_name = 1×2 cell array {'Truman'} {'Eisenhower'} names = 1×3 cell array {'John'} {'F.'} {'Kennedy'} temp_name = 1×1 cell array {'Kennedy'} last_name = 1×3 cell array {'Truman'} {'Eisenhower'} {'Kennedy'} names = 1×2 cell array {'Lyndon'} {'Johnson'} temp_name = 1×1 cell array {'Johnson'} last_name = 1×4 cell array {'Truman'} {'Eisenhower'} {'Kennedy'} {'Johnson'} names = 1×2 cell array {'Richard'} {'Nixon'} temp_name = 1×1 cell array {'Nixon'} last_name = 1×5 cell array {'Truman'} {'Eisenhower'} {'Kennedy'} {'Johnson'} {'Nixon'} names = 1×2 cell array {'Gerald'} {'Ford'} temp_name = 1×1 cell array {'Ford'} last_name = 1×6 cell array {'Truman'} {'Eisenhower'} {'Kennedy'} {'Johnson'} {'Nixon'} {'Ford'} names = 1×2 cell array {'Cleve'} {'Moler'} temp_name = 1×1 cell array {'Moler'} last_name = 1×7 cell array {'Truman'} {'Eisenhower'} {'Kennedy'} {'Johnson'} {'Nixon'} {'Ford'} {'Moler'} names = 1×2 cell array {'Ronald'} {'Reagan'} temp_name = 1×1 cell array {'Reagan'} last_name = 1×8 cell array {'Truman'} {'Eisenhower'} {'Kennedy'} {'Johnson'} {'Nixon'} {'Ford'} {'Moler'} {'Reagan'} names = 1×2 cell array {'George'} {'Bush'} temp_name = 1×1 cell array {'Bush'} last_name = 1×9 cell array {'Truman'} {'Eisenhower'} {'Kennedy'} {'Johnson'} {'Nixon'} {'Ford'} {'Moler'} {'Reagan'} {'Bush'} names = 1×2 cell array {'Bill'} {'Clinton'} temp_name = 1×1 cell array {'Clinton'} last_name = 1×10 cell array {'Truman'} {'Eisenhower'} {'Kennedy'} {'Johnson'} {'Nixon'} {'Ford'} {'Moler'} {'Reagan'} {'Bush'} {'Clinton'} names = 1×2 cell array {'George'} {'Bush'} temp_name = 1×1 cell array {'Bush'} last_name = 1×11 cell array {'Truman'} {'Eisenhower'} {'Kennedy'} {'Johnson'} {'Nixon'} {'Ford'} {'Moler'} {'Reagan'} {'Bush'} {'Clinton'} {'Bush'} names = 1×2 cell array {'Barack'} {'Obama'} temp_name = 1×1 cell array {'Obama'} last_name = 1×12 cell array {'Truman'} {'Eisenhower'} {'Kennedy'} {'Johnson'} {'Nixon'} {'Ford'} {'Moler'} {'Reagan'} {'Bush'} {'Clinton'} {'Bush'} {'Obama'} index = 9 11 10 2 6 4 3 7 5 12 8 1 alpha_list = 12×1 cell array {'George Bush' } {'George Bush' } {'Bill Clinton' } {'Dwight Eisenhower'} {'Gerald Ford' } {'Lyndon Johnson' } {'John F. Kennedy' } {'Cleve Moler' } {'Richard Nixon' } {'Barack Obama' } {'Ronald Reagan' } {'Harry Truman' }

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!