-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstl1.cpp
More file actions
151 lines (93 loc) · 2.69 KB
/
stl1.cpp
File metadata and controls
151 lines (93 loc) · 2.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#include<bits/stdc++.h>
using namespace std;
int main(){
int x = 1;
int y = 2;
swap(x, y);
cout << x << " " << y << endl; //swappppppp
cout<<min(x,y)<<endl; //will print the min one
cout<<max(x,y)<<endl;//will print the max one
cout<<__gcd(100,156)<<endl; // gshagu will take only the common divisor
string s="hello";
s=s+s; // try to avoid this cz aitai loop concatenate
cout<<s<<endl;
int z=10;
int &z2=z; // &referrence use korle z ar value o change hbe
z2=20;
cout<<z<<endl;
//VECTORRRRRRRRRRRR
vector<int>v;
cout<<"size--> "<<v.size()<<endl;
v.push_back(10);
cout<<"size--> "<<v.size()<<endl;
v.push_back(20);
v.push_back(30); // py ar append ar mto
v.push_back(40);
cout<<"size--> "<<v.size()<<endl;
cout<<v[0]<<" "<<v[2]<<endl; //specific index val check
v.pop_back(); //last element bad just like python pop
cout<<"size--> "<<v.size()<<endl;
for (int i=0; i<v.size(); i++){
cout<<v[i]<<" ";
}
cout<<endl;
vector<int> w(5); //0 diye 5 len ar vec create
for (int i=0; i<w.size(); i++){
cout<<w[i]<<" ";
}
cout<<endl;
//loop shortcut
for(int x:v){
cout<<x<<" "; //shortcut loop iterrrate
}
cout<<endl;
vector<int> k{2,3,4};//akbare 3 ta val append
for (int y: k){
cout<<y<<" ";
}
cout<<endl;
//veector string
vector<string>vst;
vst.push_back("hello");
vst.push_back("world");
for (const string &str: vst){
cout<<str<<" ";
}
cout<<endl;
//iterator
//find
vector<int>vq{1,2,3,4,5,6};
auto it=vq.begin() +3 ; //starting index nirdesh kore and +1 ar jonno next line print kroe
cout<<*it<<endl;
it=find(vq.begin(),vq.end(),2);
int pos=it-vq.begin(); //aita korle find ar index chole ashbe
cout<<pos<<endl;
//erase
vq.erase(find(vq.begin(), vq.end(),2)); // aita mane 2 vector theke remove
for (int y: vq){
cout<<y<<" ";
}
cout<<endl;
//insert
vector<int> aq{1, 2, 3, 4, 5, 6}; // Define and initialize the vector
vq.insert(aq.begin() + 2, 69); // Correct the insert function call
for (int y : aq) {
cout << y << " ";
}
cout << endl;
//reverse print
reverse(aq.begin(),aq.end());
for (int x: v){
cout<<x<<" ";
}
cout<<endl;
//sort
vector<int> vqq{5, 2, 9, 1, 5, 6}; // Define and initialize the vector
sort(vqq.begin(), vqq.end()); // Sort the vector
cout <<"sssssssss"<<endl;
for (int x : vqq) {
cout << x << " "; // Print the sorted elements
}
cout << endl;
return 0;
}