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

Info iconThis 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
Background 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

This note was uploaded on 10/21/2010 for the course CS 1371 taught by Professor Stallworth during the Spring '08 term at Georgia Institute of Technology.

Ask a homework question - tutors are online