|
unordered_set ning funksiya – a’zolari
|
bet | 5/9 | Sana | 24.05.2024 | Hajmi | 0,71 Mb. | | #252108 |
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
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.
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).
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
|
2.3 STACK simulation implementation
#include
#include
#include
#include
using namespace std;
namespace my{
template>
class stack{
public:
bool empty(){
return _con.empty();
}
size_t size(){
return _con.size();
}
T& top(){
return _con.back();
}
const T& top()const{
return back();
}
void push(const T& val){
_con.push_back(val);
}
void pop(){
_con.pop_back();
}
private:
Container _con;
};
void test_stack(){
stack s;
s.push(1);
s.push(2);
s.push(3);
s.push(4);
while (!s.empty())
{
cout << s.top() << " ";
s.pop();
}
cout << endl;
}
void test_stack1(){
stack> s;
s.push(1);
s.push(2);
s.push(3);
s.push(4);
while (!s.empty())
{
cout << s.top() << " ";
s.pop();
}
cout << endl;
}
}
Three. Queue queue
3.1 queue introduction
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.
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).
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
|
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.
#pragma once
#include
#include
#include
#include
using namespace std;
namespace my{
template>
class queue{
public:
// will call the container constructor
queue(){};
/ / Note that there is an implicit THIS pointer
size_t size()const{
return _con.size();
}
bool empty()const{
return _con.empty();
}
T& back(){
return _con.back();
}
T& front(){
return _con.front();
}
const T& back()const{
return _con.back();
}
const T& front()const{
return _con.front();
}
void push(const T& val){
_con.push_back(val);
}
void pop()
{
_con.pop_front();
}
private:
Container _con;
};
void test_queue1(){
queue q;
q.push(1);
q.push(2);
q.push(3);
q.push(4);
cout << q.size() << endl;
cout << q.back() << endl;
cout << q.front() << endl;
while (!q.empty()){
cout << q.front() << " ";
q.pop();
}
cout << endl;
}
}
Four .priority_queue priority queue
4.1Priority_Queue Introduction
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。
|
| |