Cody

Problem 70. Alphabetize by last name

Solution 2125696

Submitted on 12 Feb 2020 by Zunaed Kibria
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
list = {'Barney Google','Snuffy Smith','Dagwood Bumstead'}; alpha_list = {'Dagwood Bumstead','Barney Google','Snuffy Smith'} assert(isequal(alphabetize(list),alpha_list))

alpha_list = 1×3 cell array {'Dagwood Bumstead'} {'Barney Google'} {'Snuffy Smith'} list = 1×3 cell array {'Google Barney'} {'Snuffy Smith'} {'Dagwood Bumstead'} list = 1×3 cell array {'Google Barney'} {'Smith Snuffy'} {'Dagwood Bumstead'} list = 1×3 cell array {'Google Barney'} {'Smith Snuffy'} {'Bumstead Dagwood'} newlist = 1×3 cell array {'Bumstead Dagwood'} {'Google Barney'} {'Smith Snuffy'} newlist = 1×3 cell array {'Dagwood Bumstead'} {'Google Barney'} {'Smith Snuffy'} newlist = 1×3 cell array {'Dagwood Bumstead'} {'Barney Google'} {'Smith Snuffy'} newlist = 1×3 cell array {'Dagwood Bumstead'} {'Barney Google'} {'Snuffy Smith'}

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' } list = 12×1 cell array {'Truman Harry' } {'Dwight Eisenhower'} {'John F. Kennedy' } {'Lyndon Johnson' } {'Richard Nixon' } {'Gerald Ford' } {'Cleve Moler' } {'Ronald Reagan' } {'George Bush' } {'Bill Clinton' } {'George Bush' } {'Barack Obama' } list = 12×1 cell array {'Truman Harry' } {'Eisenhower Dwight'} {'John F. Kennedy' } {'Lyndon Johnson' } {'Richard Nixon' } {'Gerald Ford' } {'Cleve Moler' } {'Ronald Reagan' } {'George Bush' } {'Bill Clinton' } {'George Bush' } {'Barack Obama' } list = 12×1 cell array {'Truman Harry' } {'Eisenhower Dwight'} {'Kennedy John F.' } {'Lyndon Johnson' } {'Richard Nixon' } {'Gerald Ford' } {'Cleve Moler' } {'Ronald Reagan' } {'George Bush' } {'Bill Clinton' } {'George Bush' } {'Barack Obama' } list = 12×1 cell array {'Truman Harry' } {'Eisenhower Dwight'} {'Kennedy John F.' } {'Johnson Lyndon' } {'Richard Nixon' } {'Gerald Ford' } {'Cleve Moler' } {'Ronald Reagan' } {'George Bush' } {'Bill Clinton' } {'George Bush' } {'Barack Obama' } list = 12×1 cell array {'Truman Harry' } {'Eisenhower Dwight'} {'Kennedy John F.' } {'Johnson Lyndon' } {'Nixon Richard' } {'Gerald Ford' } {'Cleve Moler' } {'Ronald Reagan' } {'George Bush' } {'Bill Clinton' } {'George Bush' } {'Barack Obama' } list = 12×1 cell array {'Truman Harry' } {'Eisenhower Dwight'} {'Kennedy John F.' } {'Johnson Lyndon' } {'Nixon Richard' } {'Ford Gerald' } {'Cleve Moler' } {'Ronald Reagan' } {'George Bush' } {'Bill Clinton' } {'George Bush' } {'Barack Obama' } list = 12×1 cell array {'Truman Harry' } {'Eisenhower Dwight'} {'Kennedy John F.' } {'Johnson Lyndon' } {'Nixon Richard' } {'Ford Gerald' } {'Moler Cleve' } {'Ronald Reagan' } {'George Bush' } {'Bill Clinton' } {'George Bush' } {'Barack Obama' } list = 12×1 cell array {'Truman Harry' } {'Eisenhower Dwight'} {'Kennedy John F.' } {'Johnson Lyndon' } {'Nixon Richard' } {'Ford Gerald' } {'Moler Cleve' } {'Reagan Ronald' } {'George Bush' } {'Bill Clinton' } {'George Bush' } {'Barack Obama' } list = 12×1 cell array {'Truman Harry' } {'Eisenhower Dwight'} {'Kennedy John F.' } {'Johnson Lyndon' } {'Nixon Richard' } {'Ford Gerald' } {'Moler Cleve' } {'Reagan Ronald' } {'Bush George' } {'Bill Clinton' } {'George Bush' } {'Barack Obama' } list = 12×1 cell array {'Truman Harry' } {'Eisenhower Dwight'} {'Kennedy John F.' } {'Johnson Lyndon' } {'Nixon Richard' } {'Ford Gerald' } {'Moler Cleve' } {'Reagan Ronald' } {'Bush George' } {'Clinton Bill' } {'George Bush' } {'Barack Obama' } list = 12×1 cell array {'Truman Harry' } {'Eisenhower Dwight'} {'Kennedy John F.' } {'Johnson Lyndon' } {'Nixon Richard' } {'Ford Gerald' } {'Moler Cleve' } {'Reagan Ronald' } {'Bush George' } {'Clinton Bill' } {'Bush George' } {'Barack Obama' } list = 12×1 cell array {'Truman Harry' } {'Eisenhower Dwight'} {'Kennedy John F.' } {'Johnson Lyndon' } {'Nixon Richard' } {'Ford Gerald' } {'Moler Cleve' } {'Reagan Ronald' } {'Bush George' } {'Clinton Bill' } {'Bush George' } {'Obama Barack' } newlist = 12×1 cell array {'Bush George' } {'Bush George' } {'Clinton Bill' } {'Eisenhower Dwight'} {'Ford Gerald' } {'Johnson Lyndon' } {'Kennedy John F.' } {'Moler Cleve' } {'Nixon Richard' } {'Obama Barack' } {'Reagan Ronald' } {'Truman Harry' } newlist = 12×1 cell array {'George Bush' } {'Bush George' } {'Clinton Bill' } {'Eisenhower Dwight'} {'Ford Gerald' } {'Johnson Lyndon' } {'Kennedy John F.' } {'Moler Cleve' } {'Nixon Richard' } {'Obama Barack' } {'Reagan Ronald' } {'Truman Harry' } newlist = 12×1 cell array {'George Bush' } {'George Bush' } {'Clinton Bill' } {'Eisenhower Dwight'} {'Ford Gerald' } {'Johnson Lyndon' } {'Kennedy John F.' } {'Moler Cleve' } {'Nixon Richard' } {'Obama Barack' } {'Reagan Ronald' } {'Truman Harry' } newlist = 12×1 cell array {'George Bush' } {'George Bush' } {'Bill Clinton' } {'Eisenhower Dwight'} {'Ford Gerald' } {'Johnson Lyndon' } {'Kennedy John F.' } {'Moler Cleve' } {'Nixon Richard' } {'Obama Barack' } {'Reagan Ronald' } {'Truman Harry' } newlist = 12×1 cell array {'George Bush' } {'George Bush' } {'Bill Clinton' } {'Dwight Eisenhower'} {'Ford Gerald' } {'Johnson Lyndon' } {'Kennedy John F.' } {'Moler Cleve' } {'Nixon Richard' } {'Obama Barack' } {'Reagan Ronald' } {'Truman Harry' } newlist = 12×1 cell array {'George Bush' } {'George Bush' } {'Bill Clinton' } {'Dwight Eisenhower'} {'Gerald Ford' } {'Johnson Lyndon' } {'Kennedy John F.' } {'Moler Cleve' } {'Nixon Richard' } {'Obama Barack' } {'Reagan Ronald' } {'Truman Harry' } newlist = 12×1 cell array {'George Bush' } {'George Bush' } {'Bill Clinton' } {'Dwight Eisenhower'} {'Gerald Ford' } {'Lyndon Johnson' } {'Kennedy John F.' } {'Moler Cleve' } {'Nixon Richard' } {'Obama Barack' } {'Reagan Ronald' } {'Truman Harry' } newlist = 12×1 cell array {'George Bush' } {'George Bush' } {'Bill Clinton' } {'Dwight Eisenhower'} {'Gerald Ford' } {'Lyndon Johnson' } {'John F. Kennedy' } {'Moler Cleve' } {'Nixon Richard' } {'Obama Barack' } {'Reagan Ronald' } {'Truman Harry' } newlist = 12×1 cell array {'George Bush' } {'George Bush' } {'Bill Clinton' } {'Dwight Eisenhower'} {'Gerald Ford' } {'Lyndon Johnson' } {'John F. Kennedy' } {'Cleve Moler' } {'Nixon Richard' } {'Obama Barack' } {'Reagan Ronald' } {'Truman Harry' } newlist = 12×1 cell array {'George Bush' } {'George Bush' } {'Bill Clinton' } {'Dwight Eisenhower'} {'Gerald Ford' } {'Lyndon Johnson' } {'John F. Kennedy' } {'Cleve Moler' } {'Richard Nixon' } {'Obama Barack' } {'Reagan Ronald' } {'Truman Harry' } newlist = 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' } {'Reagan Ronald' } {'Truman Harry' } newlist = 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' } {'Truman Harry' } newlist = 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' }

Suggested Problems

More from this Author95

Community Treasure Hunt

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

Start Hunting!