Cody

Problem 70. Alphabetize by last name

Solution 1799564

Submitted on 29 Apr 2019 by CHUANQIANG ZHANG
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'} name = 1×3 cell array {0×0 double} {0×0 double} {0×0 double} temp = 2×1 cell array {'Barney'} {'Google'} name = 1×3 cell array {'Google Barney'} {0×0 double} {0×0 double} temp = 2×1 cell array {'Snuffy'} {'Smith' } name = 1×3 cell array {'Google Barney'} {'Smith Snuffy'} {0×0 double} temp = 2×1 cell array {'Dagwood' } {'Bumstead'} name = 1×3 cell array {'Google Barney'} {'Smith Snuffy'} {'Bumstead Dagwood'} name = 1×3 cell array {'Bumstead Dagwood'} {'Google Barney'} {'Smith Snuffy'} list2 = 1×3 cell array {'Bumstead Dagwood'} {'Google Barney'} {'Smith Snuffy'} name2 = 1×3 cell array {0×0 double} {0×0 double} {0×0 double} temp = 2×1 cell array {'Bumstead'} {'Dagwood' } name2 = 1×3 cell array {'Dagwood Bumstead'} {0×0 double} {0×0 double} temp = 2×1 cell array {'Google'} {'Barney'} name2 = 1×3 cell array {'Dagwood Bumstead'} {'Barney Google'} {0×0 double} temp = 2×1 cell array {'Smith' } {'Snuffy'} name2 = 1×3 cell array {'Dagwood Bumstead'} {'Barney Google'} {'Snuffy Smith'} arraysize = 1 3 name_list = 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' } name = 1×12 cell array Columns 1 through 11 {0×0 double} {0×0 double} {0×0 double} {0×0 double} {0×0 double} {0×0 double} {0×0 double} {0×0 double} {0×0 double} {0×0 double} {0×0 double} Column 12 {0×0 double} temp = 2×1 cell array {'Harry' } {'Truman'} name = 1×12 cell array Columns 1 through 10 {'Truman Harry'} {0×0 double} {0×0 double} {0×0 double} {0×0 double} {0×0 double} {0×0 double} {0×0 double} {0×0 double} {0×0 double} Columns 11 through 12 {0×0 double} {0×0 double} temp = 2×1 cell array {'Dwight' } {'Eisenhower'} name = 1×12 cell array Columns 1 through 10 {'Truman Harry'} {'Eisenhower Dwight'} {0×0 double} {0×0 double} {0×0 double} {0×0 double} {0×0 double} {0×0 double} {0×0 double} {0×0 double} Columns 11 through 12 {0×0 double} {0×0 double} temp = 3×1 cell array {'John' } {'F.' } {'Kennedy'} name = 1×12 cell array Columns 1 through 9 {'Truman Harry'} {'Eisenhower Dwight'} {'Kennedy F. John'} {0×0 double} {0×0 double} {0×0 double} {0×0 double} {0×0 double} {0×0 double} Columns 10 through 12 {0×0 double} {0×0 double} {0×0 double} temp = 2×1 cell array {'Lyndon' } {'Johnson'} name = 1×12 cell array Columns 1 through 9 {'Truman Harry'} {'Eisenhower Dwight'} {'Kennedy F. John'} {'Johnson Lyndon'} {0×0 double} {0×0 double} {0×0 double} {0×0 double} {0×0 double} Columns 10 through 12 {0×0 double} {0×0 double} {0×0 double} temp = 2×1 cell array {'Richard'} {'Nixon' } name = 1×12 cell array Columns 1 through 9 {'Truman Harry'} {'Eisenhower Dwight'} {'Kennedy F. John'} {'Johnson Lyndon'} {'Nixon Richard'} {0×0 double} {0×0 double} {0×0 double} {0×0 double} Columns 10 through 12 {0×0 double} {0×0 double} {0×0 double} temp = 2×1 cell array {'Gerald'} {'Ford' } name = 1×12 cell array Columns 1 through 9 {'Truman Harry'} {'Eisenhower Dwight'} {'Kennedy F. John'} {'Johnson Lyndon'} {'Nixon Richard'} {'Ford Gerald'} {0×0 double} {0×0 double} {0×0 double} Columns 10 through 12 {0×0 double} {0×0 double} {0×0 double} temp = 2×1 cell array {'Cleve'} {'Moler'} name = 1×12 cell array Columns 1 through 8 {'Truman Harry'} {'Eisenhower Dwight'} {'Kennedy F. John'} {'Johnson Lyndon'} {'Nixon Richard'} {'Ford Gerald'} {'Moler Cleve'} {0×0 double} Columns 9 through 12 {0×0 double} {0×0 double} {0×0 double} {0×0 double} temp = 2×1 cell array {'Ronald'} {'Reagan'} name = 1×12 cell array Columns 1 through 8 {'Truman Harry'} {'Eisenhower Dwight'} {'Kennedy F. John'} {'Johnson Lyndon'} {'Nixon Richard'} {'Ford Gerald'} {'Moler Cleve'} {'Reagan Ronald'} Columns 9 through 12 {0×0 double} {0×0 double} {0×0 double} {0×0 double} temp = 2×1 cell array {'George'} {'Bush' } name = 1×12 cell array Columns 1 through 8 {'Truman Harry'} {'Eisenhower Dwight'} {'Kennedy F. John'} {'Johnson Lyndon'} {'Nixon Richard'} {'Ford Gerald'} {'Moler Cleve'} {'Reagan Ronald'} Columns 9 through 12 {'Bush George'} {0×0 double} {0×0 double} {0×0 double} temp = 2×1 cell array {'Bill' } {'Clinton'} name = 1×12 cell array Columns 1 through 8 {'Truman Harry'} {'Eisenhower Dwight'} {'Kennedy F. John'} {'Johnson Lyndon'} {'Nixon Richard'} {'Ford Gerald'} {'Moler Cleve'} {'Reagan Ronald'} Columns 9 through 12 {'Bush George'} {'Clinton Bill'} {0×0 double} {0×0 double} temp = 2×1 cell array {'George'} {'Bush' } name = 1×12 cell array Columns 1 through 8 {'Truman Harry'} {'Eisenhower Dwight'} {'Kennedy F. John'} {'Johnson Lyndon'} {'Nixon Richard'} {'Ford Gerald'} {'Moler Cleve'} {'Reagan Ronald'} Columns 9 through 12 {'Bush George'} {'Clinton Bill'} {'Bush George'} {0×0 double} temp = 2×1 cell array {'Barack'} {'Obama' } name = 1×12 cell array Columns 1 through 8 {'Truman Harry'} {'Eisenhower Dwight'} {'Kennedy F. John'} {'Johnson Lyndon'} {'Nixon Richard'} {'Ford Gerald'} {'Moler Cleve'} {'Reagan Ronald'} Columns 9 through 12 {'Bush George'} {'Clinton Bill'} {'Bush George'} {'Obama Barack'} name = 1×12 cell array Columns 1 through 8 {'Bush George'} {'Bush George'} {'Clinton Bill'} {'Eisenhower Dwight'} {'Ford Gerald'} {'Johnson Lyndon'} {'Kennedy F. John'} {'Moler Cleve'} Columns 9 through 12 {'Nixon Richard'} {'Obama Barack'} {'Reagan Ronald'} {'Truman Harry'} list2 = 1×12 cell array Columns 1 through 8 {'Bush George'} {'Bush George'} {'Clinton Bill'} {'Eisenhower Dwight'} {'Ford Gerald'} {'Johnson Lyndon'} {'Kennedy F. John'} {'Moler Cleve'} Columns 9 through 12 {'Nixon Richard'} {'Obama Barack'} {'Reagan Ronald'} {'Truman Harry'} name2 = 1×12 cell array Columns 1 through 11 {0×0 double} {0×0 double} {0×0 double} {0×0 double} {0×0 double} {0×0 double} {0×0 double} {0×0 double} {0×0 double} {0×0 double} {0×0 double} Column 12 {0×0 double} temp = 2×1 cell array {'Bush' } {'George'} name2 = 1×12 cell array Columns 1 through 11 {'George Bush'} {0×0 double} {0×0 double} {0×0 double} {0×0 double} {0×0 double} {0×0 double} {0×0 double} {0×0 double} {0×0 double} {0×0 double} Column 12 {0×0 double} temp = 2×1 cell array {'Bush' } {'George'} name2 = 1×12 cell array Columns 1 through 10 {'George Bush'} {'George Bush'} {0×0 double} {0×0 double} {0×0 double} {0×0 double} {0×0 double} {0×0 double} {0×0 double} {0×0 double} Columns 11 through 12 {0×0 double} {0×0 double} temp = 2×1 cell array {'Clinton'} {'Bill' } name2 = 1×12 cell array Columns 1 through 10 {'George Bush'} {'George Bush'} {'Bill Clinton'} {0×0 double} {0×0 double} {0×0 double} {0×0 double} {0×0 double} {0×0 double} {0×0 double} Columns 11 through 12 {0×0 double} {0×0 double} temp = 2×1 cell array {'Eisenhower'} {'Dwight' } name2 = 1×12 cell array Columns 1 through 10 {'George Bush'} {'George Bush'} {'Bill Clinton'} {'Dwight Eisenhower'} {0×0 double} {0×0 double} {0×0 double} {0×0 double} {0×0 double} {0×0 double} Columns 11 through 12 {0×0 double} {0×0 double} temp = 2×1 cell array {'Ford' } {'Gerald'} name2 = 1×12 cell array Columns 1 through 9 {'George Bush'} {'George Bush'} {'Bill Clinton'} {'Dwight Eisenhower'} {'Gerald Ford'} {0×0 double} {0×0 double} {0×0 double} {0×0 double} Columns 10 through 12 {0×0 double} {0×0 double} {0×0 double} temp = 2×1 cell array {'Johnson'} {'Lyndon' } name2 = 1×12 cell array Columns 1 through 9 {'George Bush'} {'George Bush'} {'Bill Clinton'} {'Dwight Eisenhower'} {'Gerald Ford'} {'Lyndon Johnson'} {0×0 double} {0×0 double} {0×0 double} Columns 10 through 12 {0×0 double} {0×0 double} {0×0 double} temp = 3×1 cell array {'Kennedy'} {'F.' } {'John' } name2 = 1×12 cell array Columns 1 through 9 {'George Bush'} {'George Bush'} {'Bill Clinton'} {'Dwight Eisenhower'} {'Gerald Ford'} {'Lyndon Johnson'} {'John F. Kennedy'} {0×0 double} {0×0 double} Columns 10 through 12 {0×0 double} {0×0 double} {0×0 double} temp = 2×1 cell array {'Moler'} {'Cleve'} name2 = 1×12 cell array Columns 1 through 8 {'George Bush'} {'George Bush'} {'Bill Clinton'} {'Dwight Eisenhower'} {'Gerald Ford'} {'Lyndon Johnson'} {'John F. Kennedy'} {'Cleve Moler'} Columns 9 through 12 {0×0 double} {0×0 double} {0×0 double} {0×0 double} temp = 2×1 cell array {'Nixon' } {'Richard'} name2 = 1×12 cell array Columns 1 through 8 {'George Bush'} {'George Bush'} {'Bill Clinton'} {'Dwight Eisenhower'} {'Gerald Ford'} {'Lyndon Johnson'} {'John F. Kennedy'} {'Cleve Moler'} Columns 9 through 12 {'Richard Nixon'} {0×0 double} {0×0 double} {0×0 double} temp = 2×1 cell array {'Obama' } {'Barack'} name2 = 1×12 cell array Columns 1 through 8 {'George Bush'} {'George Bush'} {'Bill Clinton'} {'Dwight Eisenhower'} {'Gerald Ford'} {'Lyndon Johnson'} {'John F. Kennedy'} {'Cleve Moler'} Columns 9 through 12 {'Richard Nixon'} {'Barack Obama'} {0×0 double} {0×0 double} temp = 2×1 cell array {'Reagan'} {'Ronald'} name2 = 1×12 cell array Columns 1 through 8 {'George Bush'} {'George Bush'} {'Bill Clinton'} {'Dwight Eisenhower'} {'Gerald Ford'} {'Lyndon Johnson'} {'John F. Kennedy'} {'Cleve Moler'} Columns 9 through 12 {'Richard Nixon'} {'Barack Obama'} {'Ronald Reagan'} {0×0 double} temp = 2×1 cell array {'Truman'} {'Harry' } name2 = 1×12 cell array Columns 1 through 8 {'Geo...