#include <iostream>
#include <algorithm>
#include <vector>
#include <iterator>
#include <vector>
#include <string>
using namespace std;
class tropical
{
public:
string name;
int price;
};
bool sortByName(const tropical &t1, const tropical &t2); //
void displayfruits(vector<tropical>& fruitlist)
{
cout << "Name \t\tPrice" << endl << "==========\t=====" << endl;
for(int i=0;i<10;i++) //displays all fruits' names and prices
{
cout << fruitlist[i].name << " \t" << fruitlist[i].price << endl;
}
cout << endl;
}
int main()
{
int sortchoice;
string searchfruit;
string fruitname[] = {"Avocado", "Papaya", "Grapefruit", "Pineapple", "Jackfruit", "Orange", "Honeydew", "Mangosteen", "Banana", "Durian"};
int fruitprice[] = {1, 4, 6, 2, 10, 3, 9, 7, 5, 8};
vector<tropical> fruitlist;
tropical fruit;
vector<tropical>::iterator it;
for(int i=0; i<10; i++)
{
fruit.name = fruitname[i];
fruit.price = fruitprice[i];
fruitlist.push_back(fruit);
}
displayfruits(fruitlist);
sort (fruitlist.begin(), fruitlist.end(), sortByName);
displayfruits(fruitlist);
}
bool sortByName(const tropical &t1, const tropical &t2)
{
return t1.name < t2.name;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8YWxnb3JpdGhtPgojaW5jbHVkZSA8dmVjdG9yPgojaW5jbHVkZSA8aXRlcmF0b3I+CiNpbmNsdWRlIDx2ZWN0b3I+CiNpbmNsdWRlIDxzdHJpbmc+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CgpjbGFzcyB0cm9waWNhbAp7CiAgICBwdWJsaWM6CiAgICBzdHJpbmcgbmFtZTsKICAgIGludCBwcmljZTsKfTsKCmJvb2wgc29ydEJ5TmFtZShjb25zdCB0cm9waWNhbCAmdDEsIGNvbnN0ICB0cm9waWNhbCAgJnQyKTsgLy8KCnZvaWQgZGlzcGxheWZydWl0cyh2ZWN0b3I8dHJvcGljYWw+JiBmcnVpdGxpc3QpIAp7CiAgICBjb3V0IDw8ICJOYW1lIFx0XHRQcmljZSIgPDwgZW5kbCA8PCAiPT09PT09P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