#include <iostream>
#include <cstring>
using namespace std;
struct Worker
{
char pib[40];
char posada[40];
int year;
};
void InsertionSort(Worker *array, int n)
{
Worker tmp;
for (int i = 1,j; i < n; i++)
{
tmp = array[i];
for ( j=i-1; j>=0 && strcmp(array[j].pib, tmp.pib) > 0;j--)
array[j + 1] = array[j];
array[j + 1] = tmp;
}
}
int main() {
Worker arr[] = {{"ABC","DEF",1},{"XYZ","NFM",2},{"OPQ","FNF",3}};
for(auto &worker: arr)
cout<<worker.pib<<" -- "<<worker.posada<<" -- "<<worker.year<<endl;
InsertionSort(arr, 3);
cout<<"-----------------------------"<<endl;
for(auto &worker: arr)
cout<<worker.pib<<" -- "<<worker.posada<<" -- "<<worker.year<<endl;
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8Y3N0cmluZz4KCnVzaW5nIG5hbWVzcGFjZSBzdGQ7CgpzdHJ1Y3QgV29ya2VyCnsKICAgIGNoYXIgcGliWzQwXTsKICAgIGNoYXIgcG9zYWRhWzQwXTsKICAgIGludCB5ZWFyOwp9OwoKdm9pZCBJbnNlcnRpb25Tb3J0KFdvcmtlciAqYXJyYXksIGludCBuKQp7CiAgICBXb3JrZXIgIHRtcDsKICAgIGZvciAoaW50IGkgPSAxLGo7IGkgPCBuOyBpKyspCiAgICB7CiAgICAgICAgdG1wID0gYXJyYXlbaV07CiAgICAgICAgZm9yICggaj1pLTE7IGo+PTAgJiYgc3RyY21wKGFycmF5W2pdLnBpYiwgdG1wLnBpYikgPiAwO2otLSkKICAgICAgICAgICAgYXJyYXlbaiArIDFdID0gYXJyYXlbal07CiAgICAgICAgYXJyYXlbaiArIDFdID0gdG1wOwogICAgfQp9CgppbnQgbWFpbigpIHsKCVdvcmtlciBhcnJbXSA9IHt7IkFCQyIsIkRFRiIsMX0seyJYWVoiLCJORk0iLDJ9LHsiT1BRIiwiRk5GIiwzfX07Cglmb3IoYXV0byAmd29ya2VyOiBhcnIpCgkJY291dDw8d29ya2VyLnBpYjw8IiAtLSAiPDx3b3JrZXIucG9zYWRhPDwiIC0tICI8PHdvcmtlci55ZWFyPDxlbmRsOwoJSW5zZXJ0aW9uU29ydChhcnIsIDMpOwoJY291dDw8Ii0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tIjw8ZW5kbDsKCWZvcihhdXRvICZ3b3JrZXI6IGFycikKCQljb3V0PDx3b3JrZXIucGliPDwiIC0tICI8PHdvcmtlci5wb3NhZGE8PCIgLS0gIjw8d29ya2VyLnllYXI8PGVuZGw7CgkKCXJldHVybiAwOwp9