• Hash Table bilan ishlovchi funksiyalar
  • Note: There is no iterator in the container adapter. Second .stack stack 2.1 STACK introduction Stack is a kindBack first out
  • Stacks underlying container can be any standard container class
  • By default, if the container is not specified for the Stack, Deque is used by default as the default container. 2.2 STACKs use
  • Using Stack needs to include the header file include , Stack does not exist iterators. 2.3 STACK simulation implementation
  • Three. Queue queue 3.1 queue introduction Queue is a kindFirst first out ofContainer adapter
  • Bottom container is a standard container template
  • By default, it is not displayed to give the queue specified container, and Deque is used by default. 3.2 Queues use
  • Use Queue to include the header file include , Queue container adapter no iterator 3.3QUEUE simulation
  • Four .priority_queue priority queue 4.1Priority_Queue Introduction Priority queue isContainer adapter
  • unordered_set ning funksiya – a’zolari




    Download 0,71 Mb.
    bet5/9
    Sana24.05.2024
    Hajmi0,71 Mb.
    #252108
    1   2   3   4   5   6   7   8   9
    Bog'liq
    Nishonova G (D2 M2)

    unordered_set ning funksiya – a’zolari:

    Nomi

    Izoh

    at

    Ko'rsatilgan elementga indeks tekshiruvi bilan kirishni ta'minlaydi

    operator[]

    Belgilangan elementga kirishni ta'minlaydi

    front

    Birinchi elementga kirishni ta'minlaydi

    back

    oxirgi elementga kirishni ta'minlaydi

    data (C++11)

    Massivning birinchi haqiqiy elementiga ko'rsatgichni qaytaradi



    unordered_set ning funksiya – a’zolari

    Nomi

    Izoh

    get_allocator

    Bog'langan ajratuvchini qaytaradi.

    operator=

    Konteynerdagi qiymatlarni o'rnatadi



    unordered_set ning modifikatorlari:

    Nomi

    Izoh

    clear

    Konteynerni tozalaydi.

    insert

    Konteynerga element qo’shadi.

    emplace

    Elementlarni "joyida" quradi va berilgan pozitsiyadan boshlab ularni joylashtiradi.

    emplace_hint

    Foydalanish joyidagi struktura elementlari.

    erase

    Konteynerdan element ochirish.

    swap

    Tarkibni almashtirish.

    count

    Muayyan kalitga mos keladigan elementlar sonini qaytaradi.

    find

    Ma'lum bir kalitga ega bo'lgan elementni topadi.

    equal_range

    Ma'lum bir kalit uchun elementlar to'plamini qaytaradi.

    bucket_count

    Buketlar sonini qaytaradi.

    max_bucket_count

    Buketlar sonini maksimalini qaytaradi.

    bucket_size

    Aniq buketdagi elementlar soni.

    bucket

    Aniq kalitlar uchun buket qaytarish.



    Hash Table bilan ishlovchi funksiyalar:



    Nomi

    Izoh

    load_factor

    Bir buketdagi elementlarning o'rtacha sonini qaytaradi.

    max_load_factor

    O’rtach elementlar sonini maksimal boshqarish.

    rehash

    Talab qilinganidan kam bo'lmagan holda hesh jadvalini qayta tiklash.

    reserve

    Kamida belgilangan sonlar uchun joy saqlaydi.
    Bu hash jadvalini tiklaydi.

    hash_function

    Element qiymatlarini xesh qilish uchun ishlatiladigan funktsiya.

    key_eq

    Kalitlarning tengligini tekshirish funktsiyasini qaytaradi.



    unordered_set uchun qayta yuklanmagan operatorlar:



    Nomi

    Izoh

    operator==

    Bir qatordagi qiymatlarni leksikografik jihatdan taqqoslaydi

    operator!=

    unordered_set ga misol:





    unordered_set::swap ga misol:

    3.Stack, queue, priority_queue.


    What is a container adapter
    Container adapterIt is a class template encapsulated sequence container, which provides some different functions on the basis of a general sequence container.The reason why it is called a container adapter because it is an adaptable container to provide other different functions. Implement the functions we need by corresponding containers and member functions.
    The following describes three container adapters: Statk , queue , priority_queue .
    Note: There is no iterator in the container adapter.
    Second .stack stack
    2.1 STACK introduction


    1. Stack is a kindBack first outCharacteristicContainer adapter. Its deletion and insert operation can only be performed at one end of the container. That is, you can only insert and pop up on the top of the stack.

    2. Stack's underlying container can be any standard container classTemplates or other specific class containers (your design containers), but these containers must support the following: EMPTY, Back (getting the tail element), Push_Back, Pop_Back, SIZE (Get Element size).

    3. Vector, List, Deque can be used as a bottom container of Stack,By default, if the container is not specified for the Stack, Deque is used by default as the default container.


    2.2 STACK's use

    Function name

    Features

    stack()

    Construct a empty stack

    empty()

    The stack is empty, empty returns true, non-empty return FALSE

    size()

    Return to the number of stack elements

    top()

    Return to the reference of the top element

    push()

    Insert element in the top of the stack

    pop()

    Popping the Stack Stack Top Element

    Using Stack needs to include the header file #include , Stack does not exist iterators.

    2.3 STACK simulation implementation


    1. #include

    2. #include

    3. #include

    4. #include

    5. using namespace std;



    6. namespace my{

    7. template>



    8. class stack{

    9. public:

    10. bool empty(){

    11. return _con.empty();

    12. }

    13. size_t size(){

    14. return _con.size();

    15. }

    16. T& top(){

    17. return _con.back();

    18. }

    19. const T& top()const{

    20. return back();

    21. }

    22. void push(const T& val){

    23. _con.push_back(val);



    24. }

    25. void pop(){

    26. _con.pop_back();

    27. }

    28. private:

    29. Container _con;



    30. };



    31. void test_stack(){

    32. stack s;



    33. s.push(1);

    34. s.push(2);

    35. s.push(3);

    36. s.push(4);



    37. while (!s.empty())

    38. {

    39. cout << s.top() << " ";

    40. s.pop();

    41. }

    42. cout << endl;

    43. }



    44. void test_stack1(){

    45. stack> s;



    46. s.push(1);

    47. s.push(2);

    48. s.push(3);

    49. s.push(4);



    50. while (!s.empty())

    51. {

    52. cout << s.top() << " ";

    53. s.pop();

    54. }

    55. cout << endl;

    56. }

    57. }

    Three. Queue queue
    3.1 queue introduction


    1. Queue is a kindFirst first outofContainer adapterWherein is inserted from a paragraph of the container, the other end extracts the element. Insert in the tail, pop up elements on the head.

    2. Bottom container is a standard container templateOne, you can also use the container class you specifically designed, the container must support Empty (deterioration), Front (get a reference to the header element), Back (get the team tail element reference), Push_Back, POP_FRONT (Head delete), size (getting the element size).

    3. Vector, List, and Deque meet these requirements.By default, it is not displayed to give the queue specified container, and Deque is used by default.


    3.2 Queue's use

    Function declaration

    Features

    queue()

    Texture air queue

    size()

    Returns the number of elements in the queue

    empty()

    Decades whether the queue is empty

    back()

    Return to the tail element reference

    front()

    Return to the header element reference

    push()

    Insert elements in the tail

    pop()

    Pop up the header element

    Use Queue to include the header file #include , Queue container adapter no iterator

    3.3QUEUE simulation
    Because Queue exists, the package efficiency is too low using the VECTOR container, and the header needs to move the data, and the vector does not provide POP_FRONT () because the efficiency is too low.

    1. #pragma once

    2. #include

    3. #include

    4. #include

    5. #include

    6. using namespace std;



    7. namespace my{

    8. template>

    9. class queue{

    10. public:

    11. // will call the container constructor

    12. queue(){};

    13. / / Note that there is an implicit THIS pointer

    14. size_t size()const{

    15. return _con.size();

    16. }

    17. bool empty()const{

    18. return _con.empty();

    19. }

    20. T& back(){

    21. return _con.back();

    22. }

    23. T& front(){

    24. return _con.front();

    25. }

    26. const T& back()const{

    27. return _con.back();

    28. }

    29. const T& front()const{

    30. return _con.front();

    31. }

    32. void push(const T& val){

    33. _con.push_back(val);

    34. }

    35. void pop()

    36. {

    37. _con.pop_front();

    38. }

    39. private:

    40. Container _con;

    41. };



    42. void test_queue1(){

    43. queue q;

    44. q.push(1);

    45. q.push(2);

    46. q.push(3);

    47. q.push(4);



    48. cout << q.size() << endl;

    49. cout << q.back() << endl;

    50. cout << q.front() << endl;



    51. while (!q.empty()){

    52. cout << q.front() << " ";

    53. q.pop();

    54. }

    55. cout << endl;



    56. }

    57. }

    Four .priority_queue priority queue
    4.1Priority_Queue Introduction


    1. Priority queue isContainer adapter,According to if the standard is sorted, its first element is always itThe highest priority in the elements. (Maybe the value is the biggest, maybe it is the smallest),As in the data structureheap


    2. Download 0,71 Mb.
    1   2   3   4   5   6   7   8   9




    Download 0,71 Mb.

    Bosh sahifa
    Aloqalar

        Bosh sahifa



    unordered_set ning funksiya – a’zolari

    Download 0,71 Mb.