-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
git@github.com:PredyDaddy/My_CPP_Note.git
- Loading branch information
1 parent
c64552d
commit f967ed7
Showing
8 changed files
with
342 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
{ | ||
"files.associations": { | ||
"iostream": "cpp" | ||
"iostream": "cpp", | ||
"ostream": "cpp" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,49 @@ | ||
```cpp | ||
#include <iostream> | ||
#include <vector> | ||
#include <deque> | ||
|
||
using namespace std; | ||
|
||
void vec_show(const vector<int>& vec) | ||
void deq_show(deque<int> deq) | ||
{ | ||
cout<<"element: "; | ||
for (auto element : vec) | ||
cout << "Element: "; | ||
for (auto element : deq) | ||
{ | ||
cout << element << " "; | ||
} | ||
std::cout<< std::endl; | ||
cout << endl; | ||
} | ||
|
||
void func1() | ||
{ | ||
deque<int> dq = {1, 2, 3}; | ||
deq_show(dq); | ||
|
||
// 在队尾和队首插入元素 | ||
dq.push_front(20); | ||
dq.push_back(33); | ||
deq_show(dq); | ||
|
||
// 在队尾和队首删除元素 | ||
dq.pop_front(); | ||
dq.pop_back(); | ||
deq_show(dq); | ||
|
||
// 在指定元素添加删除添加 | ||
auto it = dq.begin(); | ||
it = it + 2; | ||
dq.insert(it, 99); | ||
deq_show(dq); | ||
|
||
dq.erase(it); | ||
deq_show(dq); | ||
} | ||
|
||
int main() | ||
{ | ||
// 创建int类型的vector容器 | ||
vector<int> vec; // 如果想要一个float类型的容器: vector<float> vec; | ||
|
||
// 往容器里面添加20个元素 | ||
for (int i = 0; i < 20; i++) | ||
{ | ||
vec.push_back(rand() % 100 + 1); // 往里面添加1 - 100的元素 | ||
} | ||
func1(); | ||
return 0; | ||
} | ||
|
||
``` |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#include <iostream> | ||
#include <deque> | ||
|
||
using namespace std; | ||
|
||
void deq_show(deque<int> deq) | ||
{ | ||
cout << "Element: "; | ||
for (auto element : deq) | ||
{ | ||
cout << element << " "; | ||
} | ||
cout << endl; | ||
} | ||
|
||
void func1() | ||
{ | ||
deque<int> dq = {1, 2, 3}; | ||
deq_show(dq); | ||
|
||
// 在队尾和队首插入元素 | ||
dq.push_front(20); | ||
dq.push_back(33); | ||
deq_show(dq); | ||
|
||
// 在队尾和队首删除元素 | ||
dq.pop_front(); | ||
dq.pop_back(); | ||
deq_show(dq); | ||
|
||
// 在指定元素添加删除添加 | ||
auto it = dq.begin(); | ||
it = it + 2; | ||
dq.insert(it, 99); | ||
deq_show(dq); | ||
|
||
dq.erase(it); | ||
deq_show(dq); | ||
} | ||
|
||
int main() | ||
{ | ||
|
||
func1(); | ||
return 0; | ||
} |
Binary file not shown.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.