#include <iostream>
using namespace std;
struct product{
int product_id;
string nama_product;
string kategori;
string satuan;
float harga;
string nama_perusahaan;
};
int main() {
product pd[100];
int jml_data,i;
int cari;
cin>>jml_data;
for (i=0;i<jml_data;i++){
cin>>pd[i].product_id;
cin.ignore(1000, '\n');
getline(cin,pd[i].nama_product,'\n');
getline(cin,pd[i].kategori,'\n');
getline(cin,pd[i].satuan,'\n');
cin>>pd[i].harga;
cin.ignore(1000, '\n');
getline(cin,pd[i].nama_perusahaan,'\n');
}
//proses sort dengan metode insertion sort
product pd_sort[100];
pd_sort[0] = pd[0];
for (int j = 1;j<jml_data;j++)
{
i = j - 1;
while ((0 <= i) and ( pd[j].product_id < pd_sort[i].product_id))
i = i - 1;
for (int k = j;k>=i+2;k--)
pd_sort[k] = pd_sort[k-1];
pd_sort[i+1] = pd[j];
}
//akhir proses sort dengan metode insertion sort
//cetak data
for (i=0;i<jml_data;i++){
cout<<pd_sort[i].product_id<<"\t";
cout<<pd_sort[i].nama_product<<"\t"<<pd_sort[i].kategori<<"\t"<<pd_sort[i].satuan<<"\t";
cout<<pd_sort[i].harga<<"\t"<<pd_sort[i].nama_perusahaan<<endl;
}
return 0;
}
Technorati Profile