#include<iostream>
using namespace std;
class vendor
{
long r;
string name;
public:
long v;
void read()
{
cin>>r;
cin>>name;
cin>>v;
}
void display()
{
cout<<r<<endl;
cout<<name<<endl;
}
};
vendor * search(vendor * V,int n);
vendor * search(vendor * V,int n)
{
long min=V->v;
vendor * A;
A=V;
for(int i=0;i<n;i++)
{
if(min>V->v)
{
min=V->v;
A=V;
}
V++;
}
return A;
}
int main()
{
int n;
cin>>n;
vendor V[n];
for(int i=0;i<n;i++)
{
V[i].read();
}
vendor * MINV=search(&V[0],n);
MINV->display();
return 0;
}
do you any idea what kind of question will come in skillrack for Data Structures and Algorithms
ReplyDeleteIt should initially be plain implementation of the datastructures(stack,queue,BT etc) in the form of a problem!
ReplyDeleteCould you just give a tiny explanation of what exactly happens in the search function? Thank you!
ReplyDelete1) I assign the minimum value as the first value
Delete2)Create n object pointer (A) to store reference to the object with minimum tender value.
3)the for loop iterates through the array of objects to check if it's value is less than the minimum value, if so updation occurs. (A becomes the current object)
4) Note that here no objects are directly used. We use references, as the question demands it. ('->' operator is used to access the members of an object pointer) ('.' will not work here)
Could you give a short explanation of what happens inside the search function? Thank you!
ReplyDeleteCould you please let us know how to write the pseudocode when class is there in a program? Thanks a lot!
ReplyDeleteWe will mostly use a UML diagram using 'dia' rather than a pseudocode for problems involving a class
Delete