C 學習 列表 二

2021-09-14 02:00:12 字數 1441 閱讀 1042

c++中的列表是乙個雙向鍊錶,對插入刪除的操作非常快

這兩個可以實現棧和佇列

#include #include 

using

namespace

std;

intmain

()

不同於vector,vector過載了操作符,使之可以通過下標訪問元素,而list不能,list本身是乙個雙向鍊錶,只能通過迭代器乙個乙個去訪問

#include #include #include 

using

namespace

std;

intmain();

autoit=

find(a

.begin

(),a

.end

(),30

);cout

<<(*

it);

return0;

}

using namespace std;

int main() ; auto t = find(a.begin(), a.end(), 30); a.insert(t, 50); auto it = find(a.begin(), a.end(), 50); cout << (*it); return 0; }

## 遍歷元素

### 用for迴圈遍歷

```cpp

#include #include #include using namespace std;

int main() ;

for(int n : a)

return 0;

}

int

main();

autoit=

a.begin

();while(it

!=a.end

())return0;

}

using namespace std;

int main() ; a.pop_back(); a.pop_front(); auto t = find(a.begin(), a.end(), 30); a.erase(t); auto it = a.begin(); while(it != a.end()) return 0; }

## 列表反轉

通過reserve()方法來反轉

```cpp

#include #include #include using namespace std;

int main() ;

a.reverse();

for(int n : a)

return 0;

}

??正文結束??

C 學習 列表 二

c 中的列表是乙個雙向鍊錶,對插入刪除的操作非常快 這兩個可以實現棧和佇列 include include using namespace std intmain 不同於vector,vector過載了操作符,使之可以通過下標訪問元素,而list不能,list本身是乙個雙向鍊錶,只能通過迭代器乙個乙...

C 學習日記 列表List

using system using system.collections.generic namespace sample racers.add new racer 14,niki lauda austria 25 racers.addrange new racer racers.insert 3...

python列表學習 python列表學習整理

list1 列表 是一種有序的集合,可以隨時新增和刪除其中的元素。list1 lily lucy peter abel 列印列表 print list1 遍歷列表 end 迴圈中不換行print x,end for x in list1 print x 列表個數 print len list1 列表...