• Priority_queue sinfi
  • Push(), Pop() va Top() funksiyalaridan foydalanish DEQUE
  • Masala: Ikki tomonlama navbat(deque) berilgan elementlari yig’indisini topadigan dastur yarating. include include using namespace std; int main(){
  • Mustaqil ishi mavzu: stack, queue, priority queue bajardi: qurbanboyev mirzabek qabul qildi: Urganch 2024-yil Mavzu: Stack, queue, priority queue. Ishning maqsadi




    Download 3,09 Mb.
    bet3/3
    Sana13.05.2024
    Hajmi3,09 Mb.
    #229269
    1   2   3
    Bog'liq
    stack, queue, priority queue

    int empty(struct que p) – navbat bo’shligini tekshirish.
    int size (struct que p) – navbat elementlari soni.
    Bundan tashqari navbatni inisiallash uchun quyidagi sarlavhali funksiya kiritilgan.
    void ini_que(struct que* p,int n) – Bu yerda n kiritilayotgan ma’lumotlar hajmi.
    Masala: Navbatning boshidagi va oxiridagi elementni topish dasturi:
    #include
    #include

    using namespace std;


    int main() {
    queue q;
    int n;
    cout<<"Navbat elementlari sonini kiriting: n = ";
    cin>>n;
    cout<<"Navbat elementlarini kiriting:\n";
    for(int i=1; i<=n; i++){
    int k;
    cin>>k;
    q.push(k);
    }
    cout<<"Navbatning 1-elementi: "<cout<}
    Priority_queue sinfi
    Priority_queue - har doim eng yuqori yoki eng yuqori ustuvorlikka ega bo'lgan ba'zi bir asosiy konteyner turining yuqori elementiga kirishni cheklaydigan funktsiyani cheklashni ta'minlaydigan shablon konteyner adapteri sinfidir. Priority_queue-ga yangi elementlar qo'shilishi mumkin, va prioritet_queue ustki elementi tekshirilishi yoki olib tashlanishi mumkin.
    Sintaksisi:
    template , class Compare= less > class priority_queue

    Push(), Pop() va Top() funksiyalaridan foydalanish

    DEQUE (ikki tomonlama navbat) - indekslangan ketma-ket konteyner, bu sizga elementlarni boshidan va oxiridan tezda kiritish va olib tashlash imkonini beradi. Bundan tashqari, ikki tomonlama navbatning ikkala uchiga o'rnatish va o'chirish ko'rsatgichlar va boshqa elementlarga bog'lanishlarni qoldiradi.

    Masala: Ikki tomonlama navbat(deque) berilgan elementlari yig’indisini topadigan dastur yarating.
    #include
    #include
    using namespace std;
    int main(){
    int sum=0;
    deque deq;
    deq.push_back(11);
    deq.push_back(7);
    deq.push_back(-8);
    deq.push_back(100);

    while(!deq.empty())


    {
    sum+=deq.front();
    deq.pop_front();

    }
    cout<
    }
    Natija:110

    MISOL NAMUNALARI


    Misol: sonli ketmaketlik berilgan. Ushbu sonlardan eng kattasini stekdan foydalangan holda yechish dasturini tuzing.



    Download 3,09 Mb.
    1   2   3




    Download 3,09 Mb.

    Bosh sahifa
    Aloqalar

        Bosh sahifa



    Mustaqil ishi mavzu: stack, queue, priority queue bajardi: qurbanboyev mirzabek qabul qildi: Urganch 2024-yil Mavzu: Stack, queue, priority queue. Ishning maqsadi

    Download 3,09 Mb.