{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

findBoss - %your homework or you WILL get a zero[out index...

Info icon This preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
function ca = findBoss(st,str) %Given a structure array and a string containing an employee's name, %create a cell array of employees that starts with the employee's boss, %then that person's boss, then that person's boss, etc. until an %employee is found that does not have a boss. The structures in the %array have two fields, "name", which is the name of the employee, and %"boss", which is his/her boss. Both are strings. If an employee doesn't %have a boss, their boss field will contain an empty string. Finally, %the given employee will always exist within the structure array. %You must use recursion to receive any credit. %For your convenience, the function findInStruct.m has been included %with this homework to assist you with searching through structures. %Type help findInStruct for usage information. IF you use findInStruct %then be sure to submit it with the rest of your files when you submit
Image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: %your homework, or you WILL get a zero. [out index] = findInStruct(st,'name',str); %the out is the structure where the str is found, and the index is the %place where the str was found in the structure if index==0 %determines if the index is 0, so the ca will only contain an empty %vector because the string is not in the structure ca = ; elseif isempty(st(index).boss) %terminating condition because the empty string is what will stop %the code from running ca = {}; else names = st(index).boss; %finds the name of the boss for the given index ca = [{names} findBoss(st,names)]; %calls a clone of findBoss concatenated with the string of names; %the structure will be the same but the names will be the new %string in order to find that person's boss end end...
View Full Document

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern