I have a vector of a structure..


struct employee
string name;
int age;
int empId;

and a vector of this structure

RWTValOrderedVector<employee> vec;

suppose this vector has 4 entries. Now if i want to find in this vector for employee information of a specific employeeid, how do i do that without looping through the vector and fetching each structure and comparing the empId value of each structure with the i/p?

u make a hash table where empId will be key and it will return pointer to particular structure. this will make u'r job easy.

i'm not really sure how to do that.. will try and find out ... thanks a lot ...

make two dimension array say arr[m,2] , in first dimension u store all empId, like arr[n][0]=empid
and in second dim u store pointer to corresponding structure. like arr[n][1]=ptr , then write a function which returns pointer to structure and take empid,,,,

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.