O’zbekiston Respublikasi Axborot Texnologiyalari va kommunikatsiyalarni rivojlantirish Vazirligi
Muhammad Al-Xorazmiy nomidagi
Toshkent Axborot Texnologiyalari Universiteti.
Labaratoriya ishi
Mavzu: Ustuvor navbatlar ustida bajariladigan amallar.
Bajardi: Nusratov Murodxon
4 – Laboratoriya ishi bo’yicha variantlar:
Ixtiyoriy dasturlash tilida Priority Queue strukturaga ega bo’lgan studentlar massivi ifodalovchi dastur tuzing. Ustuvorlikni student ismini bosh hariflari bo’yicha ifodalang.
Ixtiyoriy dasturlash tilida Priority Queue strukturaga ega bo’lgan studentlar massivi ifodalovchi dastur tuzing. Ustuvorlikni student familyasini bosh hariflari bo’yicha ifodalang.
Ixtiyoriy dasturlash tilida Priority Queue strukturaga ega bo’lgan studentlar massivi ifodalovchi dastur tuzing. Ustuvorlikni student yoshi bo’yicha ifodalang.
Ixtiyoriy dasturlash tilida Priority Queue strukturaga ega bo’lgan studentlar massivi ifodalovchi dastur tuzing. Ustuvorlikni student tug’ilgan yili bo’yicha ifodalang.
Ixtiyoriy dasturlash tilida Priority Queue strukturaga ega bo’lgan studentlar massivi ifodalovchi dastur tuzing. Ustuvorlikni student tug’ilgan oyi bo’yicha ifodalang.
Ixtiyoriy dasturlash tilida Priority Queue strukturaga ega bo’lgan studentlar massivi ifodalovchi dastur tuzing. Ustuvorlikni student tug’ilgan kuni bo’yicha ifodalang.
import java.util.Comparator;
import java.util.PriorityQueue;
import java.util.Random;
public class Zokir{
public static void main(String[] args) {
Random random = new Random();
Comparator comparator = new StringLengthComparator();
PriorityQueue queue = new PriorityQueue<>(10, comparator);
queue.add(new Student("Zokirjon","Karimov",18+random.nextInt(8)));
queue.add(new Student("Aziz","Sheronov",18+random.nextInt(8)));
queue.add(new Student("Laziz","Aliqulov",18+random.nextInt(8)));
queue.add(new Student("Botir","Ergashov",18+random.nextInt(8)));
queue.add(new Student("Shomurod","Ochilov",18+random.nextInt(8)));
queue.add(new Student("Shahzod","Farmonov",18+random.nextInt(8)));
while (queue.size() != 0) {
queue.remove().print();
}
}
}
class StringLengthComparator implements Comparator {
@Override
public int compare(Student x, Student y) {
if(x.age>y.age){
return -1;
}
if(x.ageage){
return 1;
}
return 0;
}
}
class Student {
String name;
String surname;
int age;
public Student(String name, String surname, int age) {
this.name = name;
this.surname = surname;
this.age = age;
}
public void print(){
System.out.println(name+" "+surname+" "+"age:"+age);
}
}
Dastur natijasi
Do'stlaringiz bilan baham: |