findBoss - %with this homework to assist you with searching...

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
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: %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 %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) ca = {}; else names = st(index).boss; ca = [{names} findBoss(st,names)]; 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 Tech.

Ask a homework question - tutors are online