Applied Algorithms - Chapter 2 (HUST) Thầy Phạm Quang Dũng

LI
lienhejb
다운로드 0회
15
0
Applied Algorithms - (HUST) GV.Phạm Quang Dũng

자료 내용

1쪽

goupee.vn goupee.com THUẬT TOÁN ỨNG DỤNG CẤU TRÚC DỮ LIỆU VÀ THƯ VIỆN Phạm Quang Dũng Bộ môn KHMT dungpq@soict.hust.edu.vn 1 fb.com/goupee.vn

2쪽

goupee.vn goupee.com NộI dung  Danh sách tuyến tính  Tập hợp  Ánh xạ  Ngăn xếp  Hàng đợi  Sắp xếp 2 fb.com/goupee.vn

3쪽

goupee.vn goupee.com Danh sách tuyến tính  Lưu trữ các đối tượng theo quan hệ tuyến tính (trước – sau)  Thao tác: thêm, xóa, tìm kiếm 3 fb.com/goupee.vn

4쪽

goupee.vn goupee.com List #include <bits/stdc++.h> using namespace std; int main(){ list<int> L; for(int i = 1; i<=5;i++){ L.push_back(i); } list<int>::iterator it; it = find(L.begin(),L.end(),3); L.insert(it,10); for(it = L.begin(); it != L.end(); it++){ cout << *it << endl; } } 4 fb.com/goupee.vn

5쪽

goupee.vn goupee.com Vector #include <bits/stdc++.h> using namespace std; int main(){ vector<int> V(3,100); // initialize 3 elements 100 for(int v = 0; v <= 10; v++) V.push_back(v); cout << "vector: "; for(int i = 0; i < V.size(); i++){ cout << V[i] << " "; } } 5 fb.com/goupee.vn

6쪽

goupee.vn goupee.com Tập hợp  Lưu các đối tượng, không trùng nhau  Thao tác: thêm, xóa, tìm kiếm 6 fb.com/goupee.vn

7쪽

goupee.vn goupee.com Tập hợp #include <bits/stdc++.h> using namespace std; int main(){ set<int> Y; for(int i = 1; i <= 10; i++){ Y.insert(i); } for(set<int>::iterator it = Y.begin(); it != Y.end(); it++){ cout << *it << endl; } if(Y.find(7) != Y.end()) cout << "Y contains 7" << endl; else cout << "Y does not contains 7" << endl; } 7 fb.com/goupee.vn

8쪽

goupee.vn goupee.com Ánh xạ  Cấu trúc dữ liệu cất trữ các cặp (khóa, giá trị)  Phục vụ tìm kiếm nhanh với khóa đầu vào 8 fb.com/goupee.vn

9쪽

goupee.vn goupee.com Ánh xạ #include <bits/stdc++.h> using namespace std; int main(){ map<int,int> m; for(int i = 1; i <= 5; i++) m.insert(pair<int,int>(i,10*i)); m[6] = 100; for(int k = 1; k <= 6; k++) cout << m[k] << endl; map<string, string> m1; m1["abc"] = "abcabc"; m1["xyz"] = "xyzxyz"; string s = "abc"; cout << m1[s] << endl; } 9 fb.com/goupee.vn

10쪽

goupee.vn goupee.com Ánh xạ #include <bits/stdc++.h> using namespace std; int main(){ map<pair<int,int>, pair<int,int> > m2; m2[pair<int,int>(2,5)] = pair<int,int>(20,50); m2[pair<int,int>(3,5)] = pair<int,int>(30,50); int i = 3; int j = 5; pair<int,int> p = m2[pair<int,int>(i,j)]; cout << p.first << "," << p.second << endl; } 10 fb.com/goupee.vn

11쪽

goupee.vn goupee.com Ngăn xếp  Cấu trúc dữ liệu cất trữ các đối tượng một cách tuyến tính  Thao tác  Thêm 1 phần tử  Lấy ra 1 phần tử  Nguyên tắc: Vào trước – ra sau 11 fb.com/goupee.vn

12쪽

goupee.vn goupee.com Hàng đợi  Cấu trúc dữ liệu cất trữ các đối tượng một cách tuyến tính  Thao tác  Thêm 1 phần tử  Lấy ra 1 phần tử  Nguyên tắc: vào trước – ra trước 12 fb.com/goupee.vn

13쪽

goupee.vn goupee.com Stack #include <bits/stdc++.h> using namespace std; int main(){ stack<int> S; for(int i = 0; i < 5; i++){ S.push(i); } while(!S.empty()){ int v = S.top(); S.pop(); cout << v << endl; }} 13 fb.com/goupee.vn

14쪽

goupee.vn goupee.com Queue #include <bits/stdc++.h> using namespace std; int main(){ queue<int> Q; for(int i = 0; i < 5; i++){ Q.push(i); } while(!Q.empty()){ int v = Q.front(); Q.pop(); cout << v << endl; } } 14 fb.com/goupee.vn

15쪽

goupee.vn goupee.com Sắp xếp #include <algorithm> #include <iostream> using namespace std; int main(){ int N = 6; double a[N] = {1.1, 5.5, 7.7, 2.2, 8.8, 3.3}; sort(a+3,a+N,greater<double>());// decreasing order for(int i = 0; i < N; i++) cout << a[i] << " "; cout << endl; sort(a,a+N); for(int i = 0; i < N; i++) cout << a[i] << " "; } 15 fb.com/goupee.vn

앞 15페이지만 표시됩니다. 전체를 보려면 자료를 다운로드하세요.

댓글 (0)

로그인 하여 토론에 참여하기

댓글이 없습니다. 첫 댓글을 남겨보세요!