Ixtiyoriy dasturlash tilida Priority Queue


Download 38.22 Kb.
Sana01.05.2020
Hajmi38.22 Kb.
#102671
Bog'liq
Ixtiyoriy dasturlash tilida Priority Queue strukturaga ega bo


  1. Ixtiyoriy dasturlash tilida Priority Queue strukturaga ega bo’lgan studentlar massivi ifodalovchi dastur tuzing. Ustuvorlikni student yoshi bo’yicha ifodalang.

#include

#include

#include

using namespace std;

#define ROW 5

#define COL 3

#define col 1

class student {

public:

int birthyear;



int birthmonth;

int birthday;

string name;

student(int birthyear, int birthmonth, int birthday,string name)

: birthyear(birthyear), birthmonth(birthmonth) , birthday(birthday), name(name)

{


}

int gethozirgiyil(){

time_t now = time(0);

tm*ltm = localtime(&now);

return 1900+ltm->tm_year;

}


int getyosh(){

int a = gethozirgiyil() - birthyear;

return a;

}


};

class Comparebirthday {

public:

bool operator()(student const& s1, student const& s2)



{

return s1.birthyear > s2.birthyear;

}

};


void show(priority_queue, Comparebirthday> Q){

while (!Q.empty()) {

student p = Q.top();

Q.pop();

cout << p.name << " " << p.birthyear<<"-"<


}

}

int main()



{

priority_queue, Comparebirthday> Q;

int arr[ROW][COL] = { { 1994, 04, 13 }, { 1991, 03, 14 }, { 1993, 11, 24 }, { 2000, 01, 14 }, { 1996, 12, 30 }};

string arr1[ROW][col] = {{"Jamshid"} , {"Farrux "}, {"Kamol "}, {"Sodiq "}, {"Alisher"}};

for (int i = 0; i < ROW; ++i) {

Q.push(student(arr[i][0], arr[i][1], arr[i][2], arr1[i][0]));

}

cout<<"Ustuvorlikni yoshi bo'yicha: \n";



cout<<"Talaba ismi: | tug'ilgan yili: | yoshi: \n";

show(Q);


return 0;

}


Download 38.22 Kb.

Do'stlaringiz bilan baham:




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling