Remember Me Forgot your Password?

Forum: Electrical & Computer Engineering :: Data Structures & Algorithms :: Stacks & Queues  New Topic
Problem #7 Reply
Author Message
nak31 Problem #7 Mon 20 Apr 2009 8:56:00 PM
Student
Joined Tues 31 Mar 2009
Posts 511

What would this program print after executing? How are they sorted inside the dictionary? If we replace NameCompare by IDCompare, how will they be sorted?

 

void main()

{Employee e;

SALdict <int,Employee,IDEmpCompare, NameCompare> EmpDict1(20);

EmpDict1.insert(Employee(15,"Nader"));

EmpDict1.insert(Employee(17,"Michael"));

EmpDict1.insert(Employee(19,"Ali"));

EmpDict1.insert(Employee(12,"Hadi"));

EmpDict1.insert(Employee(22,"Elie"));

if(EmpDict1.find(17,e))

cout<<e<<endl;


Student Rating3.9/5
nak31 Mon 20 Apr 2009 8:57:00 PM
Student
Joined Tues 31 Mar 2009
Posts 511

Solution 7:

The program should print what’s inside e. Since we have used the find function then this function should be able to find the record which has the ID=17 and store it inside e. Therefore the program should print: <17, Michael>

 

If we are using NameCompare, the records should be stored in the SAList in alphabetical order according to the name of each record, therefore they are stored in the following way:

<19, Ali>, <22,Elie>, <12,Hadi>, <17,Michael>, <15,Nader>

 

 

If we are using IDCompare, the records should be stored in the according to the ID of each record, therefore they are stored in the following way:

<12,Hadi>, <15,Nader>, <17,Michael>, <19, Ali>, <22,Elie


Student Rating3.9/5
1
© Copyright SolveMyProblem.Net 2017