├── BTL_2023 ├── graph │ ├── tempCodeRunnerFile.cpp │ ├── input.txt │ ├── input2.txt │ ├── child.txt │ ├── demo.exe │ ├── demo.cpp │ ├── output.txt │ ├── node.cpp │ ├── node_iterator.cpp │ ├── linked_list.cpp │ ├── danhsachke.cpp │ └── graphApp.cpp ├── linkedlist │ ├── demo.exe │ ├── demo.cpp │ ├── node.cpp │ ├── node_iterator.cpp │ ├── linked_list.cpp │ ├── can_bo.cpp │ ├── cbApp.cpp │ └── danh_sach_can_bo.cpp ├── 221230928 - Trương Văn Minh.pdf └── .vscode │ ├── c_cpp_properties.json │ ├── launch.json │ ├── tasks.json │ └── settings.json ├── .gitattributes ├── BSTree ├── BTREE.CPP ├── DEMO.exe ├── DemoSV.exe ├── BNODE.CPP ├── DemoSV.cpp └── DEMO.CPP ├── Vector ├── demo.exe ├── matrix.cpp ├── matrix.exe ├── vidu.exe ├── vtor.exe ├── test_myvector.exe ├── demo.cpp ├── .vscode │ ├── c_cpp_properties.json │ ├── launch.json │ └── settings.json ├── test_myvector.cpp ├── student.cpp ├── vidu.cpp ├── TestVector.cpp ├── myvector.cpp ├── stuApp.cpp └── vtor.cpp ├── quicksort ├── demo.exe ├── demo.cpp └── qsort.cpp ├── btvn_ ├── danh_ba │ ├── demo.exe │ ├── demo.cpp │ ├── test.cpp │ ├── contact.cpp │ ├── App_Contact.cpp │ ├── vector_moi.cpp │ └── addressbook.cpp ├── APP_QUAN_LY_TAI_LIEU │ ├── demo.exe │ ├── demo.cpp │ ├── .vscode │ │ ├── c_cpp_properties.json │ │ ├── launch.json │ │ ├── tasks.json │ │ └── settings.json │ ├── document.cpp │ ├── app_manager.cpp │ ├── vector_moi.cpp │ ├── user.cpp │ └── folder.cpp └── .vscode │ ├── c_cpp_properties.json │ ├── launch.json │ └── settings.json ├── ung_dung_queue ├── demo.exe ├── demo.cpp └── queue_moi.cpp ├── ung_dung_stack ├── demo.exe ├── demo.cpp └── stack.cpp ├── ung_dung_vector ├── test.exe ├── ctdl_gt.code-workspace ├── temp.cpp ├── .vscode │ ├── c_cpp_properties.json │ ├── launch.json │ └── settings.json ├── test.cpp └── vector_moi.cpp ├── ung_dung_linked_list ├── demo.exe ├── tempCodeRunnerFile.exe ├── tempCodeRunnerFile.cpp ├── demo.cpp ├── node.cpp ├── node_iterator.cpp └── linked_list.cpp ├── ung_dung_tree ├── demo.cpp └── mytree.cpp ├── .vscode ├── c_cpp_properties.json ├── launch.json ├── tasks.json └── settings.json └── BST ├── BSTree.cpp └── node.cpp /BTL_2023/graph/tempCodeRunnerFile.cpp: -------------------------------------------------------------------------------- 1 | } -------------------------------------------------------------------------------- /BTL_2023/graph/input.txt: -------------------------------------------------------------------------------- 1 | 4 3 2 | 1 2 4 3 | 2 3 5 4 | 1 4 2 5 | -------------------------------------------------------------------------------- /BTL_2023/graph/input2.txt: -------------------------------------------------------------------------------- 1 | 4 5 2 | 1 2 3 3 | 2 3 1 4 | 3 4 2 5 | 1 4 2 6 | 4 2 4 7 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /BSTree/BTREE.CPP: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mr-1504/Data_Structures_And_Algorithms/HEAD/BSTree/BTREE.CPP -------------------------------------------------------------------------------- /BSTree/DEMO.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mr-1504/Data_Structures_And_Algorithms/HEAD/BSTree/DEMO.exe -------------------------------------------------------------------------------- /BSTree/DemoSV.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mr-1504/Data_Structures_And_Algorithms/HEAD/BSTree/DemoSV.exe -------------------------------------------------------------------------------- /BTL_2023/graph/child.txt: -------------------------------------------------------------------------------- 1 | Danh sách đồ thị con: 2 | Đồ thị con thứ 1: 3 | 1 2 4 4 | 1 4 2 5 | 2 3 5 6 | -------------------------------------------------------------------------------- /Vector/demo.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mr-1504/Data_Structures_And_Algorithms/HEAD/Vector/demo.exe -------------------------------------------------------------------------------- /Vector/matrix.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mr-1504/Data_Structures_And_Algorithms/HEAD/Vector/matrix.cpp -------------------------------------------------------------------------------- /Vector/matrix.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mr-1504/Data_Structures_And_Algorithms/HEAD/Vector/matrix.exe -------------------------------------------------------------------------------- /Vector/vidu.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mr-1504/Data_Structures_And_Algorithms/HEAD/Vector/vidu.exe -------------------------------------------------------------------------------- /Vector/vtor.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mr-1504/Data_Structures_And_Algorithms/HEAD/Vector/vtor.exe -------------------------------------------------------------------------------- /quicksort/demo.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mr-1504/Data_Structures_And_Algorithms/HEAD/quicksort/demo.exe -------------------------------------------------------------------------------- /btvn_/danh_ba/demo.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mr-1504/Data_Structures_And_Algorithms/HEAD/btvn_/danh_ba/demo.exe -------------------------------------------------------------------------------- /BTL_2023/graph/demo.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mr-1504/Data_Structures_And_Algorithms/HEAD/BTL_2023/graph/demo.exe -------------------------------------------------------------------------------- /Vector/test_myvector.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mr-1504/Data_Structures_And_Algorithms/HEAD/Vector/test_myvector.exe -------------------------------------------------------------------------------- /ung_dung_queue/demo.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mr-1504/Data_Structures_And_Algorithms/HEAD/ung_dung_queue/demo.exe -------------------------------------------------------------------------------- /ung_dung_stack/demo.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mr-1504/Data_Structures_And_Algorithms/HEAD/ung_dung_stack/demo.exe -------------------------------------------------------------------------------- /ung_dung_vector/test.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mr-1504/Data_Structures_And_Algorithms/HEAD/ung_dung_vector/test.exe -------------------------------------------------------------------------------- /BTL_2023/graph/demo.cpp: -------------------------------------------------------------------------------- 1 | #include "graphApp.cpp" 2 | using namespace std; 3 | int main() 4 | { 5 | app a; 6 | a.run(); 7 | } -------------------------------------------------------------------------------- /BTL_2023/linkedlist/demo.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mr-1504/Data_Structures_And_Algorithms/HEAD/BTL_2023/linkedlist/demo.exe -------------------------------------------------------------------------------- /ung_dung_linked_list/demo.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mr-1504/Data_Structures_And_Algorithms/HEAD/ung_dung_linked_list/demo.exe -------------------------------------------------------------------------------- /btvn_/APP_QUAN_LY_TAI_LIEU/demo.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mr-1504/Data_Structures_And_Algorithms/HEAD/btvn_/APP_QUAN_LY_TAI_LIEU/demo.exe -------------------------------------------------------------------------------- /BTL_2023/linkedlist/demo.cpp: -------------------------------------------------------------------------------- 1 | #include "cbApp.cpp" 2 | using namespace std; 3 | int main() 4 | { 5 | app a; 6 | a.run(); 7 | return 0; 8 | } -------------------------------------------------------------------------------- /BTL_2023/221230928 - Trương Văn Minh.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mr-1504/Data_Structures_And_Algorithms/HEAD/BTL_2023/221230928 - Trương Văn Minh.pdf -------------------------------------------------------------------------------- /ung_dung_linked_list/tempCodeRunnerFile.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mr-1504/Data_Structures_And_Algorithms/HEAD/ung_dung_linked_list/tempCodeRunnerFile.exe -------------------------------------------------------------------------------- /Vector/demo.cpp: -------------------------------------------------------------------------------- 1 | #include"conio.h" 2 | #include"stdio.h" 3 | #include"StuApp.cpp" 4 | int main() 5 | { 6 | VectorApp x; 7 | x.run(); 8 | return 0; 9 | } 10 | 11 | -------------------------------------------------------------------------------- /ung_dung_vector/ctdl_gt.code-workspace: -------------------------------------------------------------------------------- 1 | { 2 | "folders": [ 3 | { 4 | "path": ".." 5 | } 6 | ], 7 | "settings": { 8 | "files.associations": { 9 | "iostream": "cpp" 10 | } 11 | } 12 | } -------------------------------------------------------------------------------- /btvn_/danh_ba/demo.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "App_contact.cpp" 3 | using namespace std; 4 | int main() 5 | { 6 | app a; 7 | a.run(); 8 | a.end_task(); 9 | return 0; 10 | } -------------------------------------------------------------------------------- /btvn_/APP_QUAN_LY_TAI_LIEU/demo.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "app_manager.cpp" 3 | using namespace std; 4 | int main() 5 | { 6 | app a; 7 | a.home(); 8 | a.end_task(); 9 | return 0; 10 | } -------------------------------------------------------------------------------- /ung_dung_queue/demo.cpp: -------------------------------------------------------------------------------- 1 | #include "queue_moi.cpp" 2 | using namespace std; 3 | int main(){ 4 | queue_moia; 5 | a.push(5); 6 | a.push(6); 7 | a.front()=7; 8 | cout< 2 | #include "vector_moi.cpp" 3 | using namespace std; 4 | int main(){ 5 | vector_moi a; 6 | a.them_cuoi(2); 7 | a.them_cuoi(1); 8 | sort(a.begin(), a.end()); 9 | } -------------------------------------------------------------------------------- /ung_dung_linked_list/tempCodeRunnerFile.cpp: -------------------------------------------------------------------------------- 1 | #include "linked_list.cpp" 2 | using namespace std; 3 | int main(){ 4 | Don_list a; 5 | cout< a; 5 | a.push(1); 6 | a.push(2); 7 | a.push(2); 8 | a.push(2); 9 | a.push(-1); 10 | a.print(); 11 | } -------------------------------------------------------------------------------- /quicksort/demo.cpp: -------------------------------------------------------------------------------- 1 | #include "qsort.cpp" 2 | using namespace std; 3 | int main() 4 | { 5 | int n; 6 | char a[5]; 7 | for (int i = 0; i < 5; i++) 8 | cin >> a[i]; 9 | q_sort(a, 0, 4); 10 | for (int i = 0; i < 5; i++) 11 | cout << a[i] << " "; 12 | } -------------------------------------------------------------------------------- /BTL_2023/graph/output.txt: -------------------------------------------------------------------------------- 1 | Số đỉnh: 4 2 | Đỉnh 1 kết nối với: 3 | Đỉnh 2 có trọng số 4 4 | Đỉnh 4 có trọng số 2 5 | 6 | Đỉnh 2 kết nối với: 7 | Đỉnh 1 có trọng số 4 8 | Đỉnh 3 có trọng số 5 9 | 10 | Đỉnh 3 kết nối với: 11 | Đỉnh 2 có trọng số 5 12 | 13 | Đỉnh 4 kết nối với: 14 | Đỉnh 1 có trọng số 2 15 | 16 | -------------------------------------------------------------------------------- /ung_dung_linked_list/demo.cpp: -------------------------------------------------------------------------------- 1 | #include "linked_list.cpp" 2 | using namespace std; 3 | int main() 4 | { 5 | Don_list a; 6 | cout << a.size() << endl; 7 | int n; 8 | cin >> n; 9 | a.push_back(n); 10 | cout << a.size() << endl; 11 | a.push_back(5); 12 | cout << a.front() << " " << a.back(); 13 | } -------------------------------------------------------------------------------- /ung_dung_stack/demo.cpp: -------------------------------------------------------------------------------- 1 | #include "stack.cpp" 2 | using namespace std; 3 | int main() 4 | { 5 | stack_moi a; 6 | cout << a.top() << " " << a.size() << endl; 7 | a.push(1); 8 | a.push(2); 9 | cout << a.top() << " " << a.size() << endl; 10 | a.pop(); 11 | cout << a.top() << " " << a.size() << endl; 12 | } -------------------------------------------------------------------------------- /.vscode/c_cpp_properties.json: -------------------------------------------------------------------------------- 1 | { 2 | "configurations": [ 3 | { 4 | "name": "windows-gcc-x64", 5 | "includePath": [ 6 | "${workspaceFolder}/**" 7 | ], 8 | "compilerPath": "C:/mingw32/bin/gcc.exe", 9 | "cStandard": "${default}", 10 | "cppStandard": "${default}", 11 | "intelliSenseMode": "windows-gcc-x64", 12 | "compilerArgs": [ 13 | "" 14 | ] 15 | } 16 | ], 17 | "version": 4 18 | } -------------------------------------------------------------------------------- /BTL_2023/.vscode/c_cpp_properties.json: -------------------------------------------------------------------------------- 1 | { 2 | "configurations": [ 3 | { 4 | "name": "windows-gcc-x64", 5 | "includePath": [ 6 | "${workspaceFolder}/**" 7 | ], 8 | "compilerPath": "C:/mingw32/bin/gcc.exe", 9 | "cStandard": "${default}", 10 | "cppStandard": "${default}", 11 | "intelliSenseMode": "windows-gcc-x64", 12 | "compilerArgs": [ 13 | "" 14 | ] 15 | } 16 | ], 17 | "version": 4 18 | } -------------------------------------------------------------------------------- /Vector/.vscode/c_cpp_properties.json: -------------------------------------------------------------------------------- 1 | { 2 | "configurations": [ 3 | { 4 | "name": "windows-gcc-x64", 5 | "includePath": [ 6 | "${workspaceFolder}/**" 7 | ], 8 | "compilerPath": "C:/mingw32/bin/gcc.exe", 9 | "cStandard": "${default}", 10 | "cppStandard": "${default}", 11 | "intelliSenseMode": "windows-gcc-x64", 12 | "compilerArgs": [ 13 | "" 14 | ] 15 | } 16 | ], 17 | "version": 4 18 | } -------------------------------------------------------------------------------- /btvn_/.vscode/c_cpp_properties.json: -------------------------------------------------------------------------------- 1 | { 2 | "configurations": [ 3 | { 4 | "name": "windows-gcc-x64", 5 | "includePath": [ 6 | "${workspaceFolder}/**" 7 | ], 8 | "compilerPath": "C:/mingw32/bin/gcc.exe", 9 | "cStandard": "${default}", 10 | "cppStandard": "${default}", 11 | "intelliSenseMode": "windows-gcc-x64", 12 | "compilerArgs": [ 13 | "" 14 | ] 15 | } 16 | ], 17 | "version": 4 18 | } -------------------------------------------------------------------------------- /ung_dung_vector/.vscode/c_cpp_properties.json: -------------------------------------------------------------------------------- 1 | { 2 | "configurations": [ 3 | { 4 | "name": "windows-gcc-x64", 5 | "includePath": [ 6 | "${workspaceFolder}/**" 7 | ], 8 | "compilerPath": "C:/mingw32/bin/gcc.exe", 9 | "cStandard": "${default}", 10 | "cppStandard": "${default}", 11 | "intelliSenseMode": "windows-gcc-x64", 12 | "compilerArgs": [ 13 | "" 14 | ] 15 | } 16 | ], 17 | "version": 4 18 | } -------------------------------------------------------------------------------- /btvn_/APP_QUAN_LY_TAI_LIEU/.vscode/c_cpp_properties.json: -------------------------------------------------------------------------------- 1 | { 2 | "configurations": [ 3 | { 4 | "name": "windows-gcc-x64", 5 | "includePath": [ 6 | "${workspaceFolder}/**" 7 | ], 8 | "compilerPath": "C:/mingw32/bin/gcc.exe", 9 | "cStandard": "${default}", 10 | "cppStandard": "${default}", 11 | "intelliSenseMode": "windows-gcc-x64", 12 | "compilerArgs": [ 13 | "" 14 | ] 15 | } 16 | ], 17 | "version": 4 18 | } -------------------------------------------------------------------------------- /BTL_2023/linkedlist/node.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #ifndef _node_CPP 3 | #define _node_CPP 4 | using namespace std; 5 | template 6 | class node 7 | { 8 | T data; 9 | node *next; 10 | 11 | public: 12 | node() {} 13 | node(T data) 14 | { 15 | next = new node; 16 | next = nullptr; 17 | this->data = data; 18 | } 19 | void setE(T x) { data = x; } 20 | void setNext(node *x) { next = x; } 21 | T &getE() { return data; } 22 | node *&getNext() { return next; } 23 | ~node() 24 | { 25 | delete next; 26 | } 27 | }; 28 | #endif -------------------------------------------------------------------------------- /ung_dung_linked_list/node.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #ifndef _node_CPP 3 | #define _node_CPP 4 | using namespace std; 5 | template 6 | class node 7 | { 8 | T data; 9 | node *next; 10 | 11 | public: 12 | node() {} 13 | node(T data) 14 | { 15 | next = new node; 16 | next = nullptr; 17 | this->data = data; 18 | } 19 | void setE(T x) { data = x; } 20 | void setNext(node *x) { next = x; } 21 | T &getE() { return data; } 22 | node *&getNext() { return next; } 23 | ~node() 24 | { 25 | delete next; 26 | } 27 | }; 28 | #endif -------------------------------------------------------------------------------- /BTL_2023/graph/node.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #ifndef _node_CPP 3 | #define _node_CPP 4 | using namespace std; 5 | template 6 | class node 7 | { 8 | T data; 9 | node *next; 10 | 11 | public: 12 | node() {} 13 | node(T data) 14 | { 15 | next = new node; 16 | next = nullptr; 17 | this->data = data; 18 | } 19 | node &operator = (const node&x){ 20 | data=x.data; 21 | next = x.next; 22 | return *this; 23 | } 24 | void setE(T x) { data = x; } 25 | void setNext(node *x) { next = x; } 26 | T &getE() { return data; } 27 | node *&getNext() { return next; } 28 | ~node() 29 | { 30 | delete next; 31 | } 32 | }; 33 | #endif -------------------------------------------------------------------------------- /Vector/test_myvector.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include"myvector.cpp" 3 | using namespace std; 4 | void in(myVector v) 5 | { 6 | for(int i=0;i v; 13 | v.push_back(10); 14 | v.push_back(100); 15 | v.push_back(1000); 16 | v.push_back(10000); 17 | //v.insert(2,500); 18 | 19 | cout<<"Vector v:"; 20 | in(v); 21 | cout<<"\n Duyet vector bang bo lap xuoi:"; 22 | myVector::iterator it; 23 | for(it = v.begin(); it!=v.end(); it++) 24 | cout<<*it <<"\t"; 25 | cout<<"\n Duyet vector bang bo lap nguoc:"; 26 | myVector::reverse_iterator rit ; 27 | for(rit = v.rbegin(); rit!=v.rend(); rit++) 28 | cout<<*rit <<"\t"; 29 | 30 | } 31 | -------------------------------------------------------------------------------- /BST/BSTree.cpp: -------------------------------------------------------------------------------- 1 | #include "node.cpp" 2 | #ifndef _bstree__cpp_ 3 | #define _bstree__cpp_ 4 | using namespace std; 5 | 6 | template 7 | class bsTree{ 8 | node *root; 9 | long long count; 10 | 11 | public: 12 | bsTree(){ 13 | root = nullptr; 14 | count = 0; 15 | } 16 | long long size(){return count;} 17 | bool is_empty(){ return root == nullptr;} 18 | bool is_in(node *p){ return p->has_L() || p->has_r();} 19 | bool is_ex(node *p){ 20 | if(p->has_r() || p->has_L()) 21 | return 0; 22 | else 23 | return 1; 24 | } 25 | bool is_Root(node *p){ 26 | return p->getPa()==nullptr; 27 | } 28 | 29 | }; 30 | #endif -------------------------------------------------------------------------------- /.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "0.2.0", 3 | "configurations": [ 4 | { 5 | "name": "C/C++ Runner: Debug Session", 6 | "type": "cppdbg", 7 | "request": "launch", 8 | "args": [], 9 | "stopAtEntry": false, 10 | "externalConsole": true, 11 | "cwd": "d:/minh/desktop/Desktop/code/Data_Structures_And_Algorithms/BSTree", 12 | "program": "d:/minh/desktop/Desktop/code/Data_Structures_And_Algorithms/BSTree/build/Debug/outDebug", 13 | "MIMode": "gdb", 14 | "miDebuggerPath": "gdb", 15 | "setupCommands": [ 16 | { 17 | "description": "Enable pretty-printing for gdb", 18 | "text": "-enable-pretty-printing", 19 | "ignoreFailures": true 20 | } 21 | ] 22 | } 23 | ] 24 | } -------------------------------------------------------------------------------- /Vector/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "0.2.0", 3 | "configurations": [ 4 | { 5 | "name": "C/C++ Runner: Debug Session", 6 | "type": "cppdbg", 7 | "request": "launch", 8 | "args": [], 9 | "stopAtEntry": false, 10 | "externalConsole": true, 11 | "cwd": "d:/minh/desktop/Desktop/code/Data_Structures_And_Algorithms/Vector", 12 | "program": "d:/minh/desktop/Desktop/code/Data_Structures_And_Algorithms/Vector/build/Debug/outDebug", 13 | "MIMode": "gdb", 14 | "miDebuggerPath": "gdb", 15 | "setupCommands": [ 16 | { 17 | "description": "Enable pretty-printing for gdb", 18 | "text": "-enable-pretty-printing", 19 | "ignoreFailures": true 20 | } 21 | ] 22 | } 23 | ] 24 | } -------------------------------------------------------------------------------- /btvn_/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "0.2.0", 3 | "configurations": [ 4 | { 5 | "name": "C/C++ Runner: Debug Session", 6 | "type": "cppdbg", 7 | "request": "launch", 8 | "args": [], 9 | "stopAtEntry": false, 10 | "externalConsole": true, 11 | "cwd": "d:/minh/desktop/Desktop/code/Data_Structures_And_Algorithms/btvn_/danh_ba", 12 | "program": "d:/minh/desktop/Desktop/code/Data_Structures_And_Algorithms/btvn_/danh_ba/build/Debug/outDebug", 13 | "MIMode": "gdb", 14 | "miDebuggerPath": "gdb", 15 | "setupCommands": [ 16 | { 17 | "description": "Enable pretty-printing for gdb", 18 | "text": "-enable-pretty-printing", 19 | "ignoreFailures": true 20 | } 21 | ] 22 | } 23 | ] 24 | } -------------------------------------------------------------------------------- /BTL_2023/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "0.2.0", 3 | "configurations": [ 4 | { 5 | "name": "C/C++ Runner: Debug Session", 6 | "type": "cppdbg", 7 | "request": "launch", 8 | "args": [], 9 | "stopAtEntry": false, 10 | "externalConsole": true, 11 | "cwd": "d:/minh/desktop/Desktop/code/Data_Structures_And_Algorithms/BTL_2023/graph", 12 | "program": "d:/minh/desktop/Desktop/code/Data_Structures_And_Algorithms/BTL_2023/graph/build/Debug/outDebug", 13 | "MIMode": "gdb", 14 | "miDebuggerPath": "gdb", 15 | "setupCommands": [ 16 | { 17 | "description": "Enable pretty-printing for gdb", 18 | "text": "-enable-pretty-printing", 19 | "ignoreFailures": true 20 | } 21 | ] 22 | } 23 | ] 24 | } -------------------------------------------------------------------------------- /ung_dung_vector/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "0.2.0", 3 | "configurations": [ 4 | { 5 | "name": "C/C++ Runner: Debug Session", 6 | "type": "cppdbg", 7 | "request": "launch", 8 | "args": [], 9 | "stopAtEntry": false, 10 | "externalConsole": true, 11 | "cwd": "d:/minh/desktop/Desktop/code/Data_Structures_And_Algorithms/ung_dung_vector", 12 | "program": "d:/minh/desktop/Desktop/code/Data_Structures_And_Algorithms/ung_dung_vector/build/Debug/outDebug", 13 | "MIMode": "gdb", 14 | "miDebuggerPath": "gdb", 15 | "setupCommands": [ 16 | { 17 | "description": "Enable pretty-printing for gdb", 18 | "text": "-enable-pretty-printing", 19 | "ignoreFailures": true 20 | } 21 | ] 22 | } 23 | ] 24 | } -------------------------------------------------------------------------------- /Vector/student.cpp: -------------------------------------------------------------------------------- 1 | #ifndef STUDENT_CPP 2 | #include"conio.h" 3 | #include"iostream" 4 | using namespace std; 5 | class Student 6 | { 7 | private: 8 | int masv; 9 | char hoten[30]; 10 | char gioi[4]; 11 | public: 12 | int getmasv(){ 13 | return masv; 14 | } 15 | friend istream & operator >>(istream &is, Student &s); 16 | friend ostream & operator <<(ostream &os, Student s); 17 | }; 18 | 19 | istream & operator >>(istream &is, Student &s) 20 | { 21 | cout<<"\nNhap ma sv:"; 22 | is>>s.masv; 23 | cout<<"Nhap ho va ten:"; 24 | is.ignore(1); 25 | is.get(s.hoten,30); 26 | cout<<"Nhap gioi tinh:"; 27 | is.ignore(1); 28 | is.get(s.gioi,4); 29 | return is; 30 | } 31 | ostream & operator <<(ostream &os, Student s) 32 | { 33 | os< 6 | class iter 7 | { 8 | node *a; 9 | 10 | public: 11 | iter() { a = nullptr; } 12 | iter(node *x) { a = x; } 13 | node *getnode() { return a; } 14 | iter &operator=(iter x) 15 | { 16 | this->a = x.getnode(); 17 | return *this; 18 | } 19 | bool operator!=(iter x) { return a != x.getnode(); } 20 | iter operator++() 21 | { 22 | a->getNext(); 23 | return a; 24 | } 25 | iter operator++(int) 26 | { 27 | iter temp=*this; 28 | a = a->getNext(); 29 | return temp; 30 | } 31 | T &operator*() 32 | { 33 | return a->getE(); 34 | } 35 | }; 36 | #endif -------------------------------------------------------------------------------- /ung_dung_linked_list/node_iterator.cpp: -------------------------------------------------------------------------------- 1 | #include "node.cpp" 2 | #ifndef _iterator_CPP 3 | #define _iterator_CPP 4 | using namespace std; 5 | template 6 | class iter 7 | { 8 | node *a; 9 | 10 | public: 11 | iter() { a = nullptr; } 12 | iter(node *x) { a = x; } 13 | node *getnode() { return a; } 14 | iter &operator=(iter x) 15 | { 16 | this->a = x.getnode(); 17 | return *this; 18 | } 19 | bool operator!=(iter x) { return a != x.getnode(); } 20 | iter operator++() 21 | { 22 | a->getNext(); 23 | return a; 24 | } 25 | iter operator++(int) 26 | { 27 | node *temp; 28 | a = a->getNext(); 29 | return temp; 30 | } 31 | T &operator*() 32 | { 33 | return a->getE(); 34 | } 35 | }; 36 | #endif -------------------------------------------------------------------------------- /BTL_2023/linkedlist/node_iterator.cpp: -------------------------------------------------------------------------------- 1 | #include "node.cpp" 2 | #ifndef _iterator_CPP 3 | #define _iterator_CPP 4 | using namespace std; 5 | template 6 | class iter 7 | { 8 | node *a; 9 | 10 | public: 11 | iter() { a = nullptr; } 12 | iter(node *x) { a = x; } 13 | node *getnode() { return a; } 14 | iter &operator=(iter x) 15 | { 16 | this->a = x.getnode(); 17 | return *this; 18 | } 19 | bool operator!=(iter x) { return a != x.getnode(); } 20 | iter operator++() 21 | { 22 | a->getNext(); 23 | return a; 24 | } 25 | iter operator++(int) 26 | { 27 | iter temp = *this; 28 | a = a->getNext(); 29 | return temp; 30 | } 31 | T &operator*() 32 | { 33 | return a->getE(); 34 | } 35 | }; 36 | #endif -------------------------------------------------------------------------------- /btvn_/APP_QUAN_LY_TAI_LIEU/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "0.2.0", 3 | "configurations": [ 4 | { 5 | "name": "C/C++ Runner: Debug Session", 6 | "type": "cppdbg", 7 | "request": "launch", 8 | "args": [], 9 | "stopAtEntry": false, 10 | "externalConsole": true, 11 | "cwd": "d:/minh/desktop/Desktop/code/Data_Structures_And_Algorithms/btvn_/APP_QUAN_LY_TAI_LIEU", 12 | "program": "d:/minh/desktop/Desktop/code/Data_Structures_And_Algorithms/btvn_/APP_QUAN_LY_TAI_LIEU/build/Debug/outDebug", 13 | "MIMode": "gdb", 14 | "miDebuggerPath": "gdb", 15 | "setupCommands": [ 16 | { 17 | "description": "Enable pretty-printing for gdb", 18 | "text": "-enable-pretty-printing", 19 | "ignoreFailures": true 20 | } 21 | ] 22 | } 23 | ] 24 | } -------------------------------------------------------------------------------- /.vscode/tasks.json: -------------------------------------------------------------------------------- 1 | { 2 | "tasks": [ 3 | { 4 | "type": "cppbuild", 5 | "label": "C/C++: g++.exe build active file", 6 | "command": "C:\\mingw32\\bin\\g++.exe", 7 | "args": [ 8 | "-fdiagnostics-color=always", 9 | "-g", 10 | "${file}", 11 | "-o", 12 | "${fileDirname}\\${fileBasenameNoExtension}.exe" 13 | ], 14 | "options": { 15 | "cwd": "${fileDirname}" 16 | }, 17 | "problemMatcher": [ 18 | "$gcc" 19 | ], 20 | "group": { 21 | "kind": "build", 22 | "isDefault": true 23 | }, 24 | "detail": "Task generated by Debugger." 25 | } 26 | ], 27 | "version": "2.0.0" 28 | } -------------------------------------------------------------------------------- /BTL_2023/.vscode/tasks.json: -------------------------------------------------------------------------------- 1 | { 2 | "tasks": [ 3 | { 4 | "type": "cppbuild", 5 | "label": "C/C++: g++.exe build active file", 6 | "command": "C:\\mingw32\\bin\\g++.exe", 7 | "args": [ 8 | "-fdiagnostics-color=always", 9 | "-g", 10 | "${file}", 11 | "-o", 12 | "${fileDirname}\\${fileBasenameNoExtension}.exe" 13 | ], 14 | "options": { 15 | "cwd": "${fileDirname}" 16 | }, 17 | "problemMatcher": [ 18 | "$gcc" 19 | ], 20 | "group": { 21 | "kind": "build", 22 | "isDefault": true 23 | }, 24 | "detail": "Task generated by Debugger." 25 | } 26 | ], 27 | "version": "2.0.0" 28 | } -------------------------------------------------------------------------------- /btvn_/APP_QUAN_LY_TAI_LIEU/.vscode/tasks.json: -------------------------------------------------------------------------------- 1 | { 2 | "tasks": [ 3 | { 4 | "type": "cppbuild", 5 | "label": "C/C++: g++.exe build active file", 6 | "command": "C:\\mingw32\\bin\\g++.exe", 7 | "args": [ 8 | "-fdiagnostics-color=always", 9 | "-g", 10 | "${file}", 11 | "-o", 12 | "${fileDirname}\\${fileBasenameNoExtension}.exe" 13 | ], 14 | "options": { 15 | "cwd": "${fileDirname}" 16 | }, 17 | "problemMatcher": [ 18 | "$gcc" 19 | ], 20 | "group": { 21 | "kind": "build", 22 | "isDefault": true 23 | }, 24 | "detail": "Task generated by Debugger." 25 | } 26 | ], 27 | "version": "2.0.0" 28 | } -------------------------------------------------------------------------------- /Vector/vidu.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | vector v; 7 | int n; 8 | float x; 9 | cout<<"Nhap n="; 10 | cin>>n; 11 | for(int i=0;i::iterator it; 22 | for(it = v.begin(); it!=v.end();it++) 23 | cout<<*it<<" "; 24 | cout<<"\n In cac phan tu bang cach su dung bo lap nguoc:"; 25 | vector::reverse_iterator rit ; 26 | for(rit = v.rbegin(); rit!=v.rend();rit++) 27 | cout<<*rit<<" "; 28 | 29 | it = v.begin(); 30 | it++; 31 | v.erase(it); 32 | cout<<"\nCac phan tu hien co trong vector:"; 33 | for(int i=0;i 2 | #ifndef _q_sort_cpp_ 3 | #define _q_sort_cpp_ 4 | using namespace std; 5 | 6 | template 7 | void swapp(T &a, T &b) 8 | { 9 | T temp = a; 10 | a = b; 11 | b = a; 12 | } 13 | 14 | template 15 | void partition(T *a, int i, int j, int &right) 16 | { 17 | T p = a[i]; 18 | int left = i; 19 | right = j; 20 | while (left <= right) 21 | { 22 | while (a[left] <= p && left <= right) 23 | left++; 24 | while (a[right] > p ) 25 | right--;\ 26 | if (left < right) 27 | swapp(a[left], a[right]); 28 | } 29 | a[i] = a[right]; 30 | a[right] = p; 31 | } 32 | 33 | template 34 | void q_sort(T *a, int i, int j){ 35 | if(i < j){ 36 | int right = j; 37 | partition(a, i, j, right); 38 | q_sort(a, i, right); 39 | q_sort(a, right + 1, j); 40 | } 41 | } 42 | 43 | #endif -------------------------------------------------------------------------------- /BSTree/BNODE.CPP: -------------------------------------------------------------------------------- 1 | #ifndef NODE_H 2 | #define NODE_H 1 3 | #include"stdio.h" 4 | template 5 | class BNode{ 6 | private: 7 | Keys key; 8 | T elem; 9 | BNode *parent; 10 | BNode *left; 11 | BNode *right; 12 | public: 13 | BNode(){ 14 | parent = NULL; 15 | left = NULL; 16 | right = NULL; 17 | } 18 | BNode *getParent() { return parent;} 19 | BNode *getLeft() { return left;} 20 | BNode *getRight() { return right;} 21 | void setLeft(BNode* p){ left = p;} 22 | void setRight(BNode* p) {right = p;} 23 | void setParent(BNode* p) {parent= p;} 24 | int hasLeft() { return left!=NULL; } 25 | int hasRight() { return right!=NULL;} 26 | T getElem(){ return elem;} 27 | void setElem(T e) { elem =e;} 28 | Keys getKey(){ return key;} 29 | void setKey(Keys k){ key = k; } 30 | }; 31 | #endif 32 | -------------------------------------------------------------------------------- /ung_dung_stack/stack.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #ifndef _stack_cpp 3 | #define _stack_cpp 4 | using namespace std; 5 | template 6 | class stack_moi 7 | { 8 | int n, cap; 9 | T *a; 10 | 11 | public: 12 | stack_moi() 13 | { 14 | n = cap = 0; 15 | a = nullptr; 16 | } 17 | ~stack_moi() 18 | { 19 | delete[] a; 20 | } 21 | bool emtyl() { return n == 0; } 22 | int size() { return n; } 23 | void pop() 24 | { 25 | if (n) 26 | n--; 27 | } 28 | void extend(int t) 29 | { 30 | if (cap == t) 31 | cap = t * 2; 32 | else 33 | return; 34 | T *temp = new T[cap]; 35 | for (int i; i < n; i++) 36 | temp[i] = a[i]; 37 | delete[] a; 38 | a = temp; 39 | } 40 | void push(int t) 41 | { 42 | extend(n); 43 | a[n++] = t; 44 | } 45 | T &top() { return n != 0 ? a[n - 1]; } 46 | }; 47 | #endif -------------------------------------------------------------------------------- /BST/node.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #ifndef _node_bst_ 3 | #define _node_bst_ 4 | using namespace std; 5 | 6 | template 7 | class node 8 | { 9 | key k; 10 | T elem; 11 | node *pa; 12 | node *l; 13 | node *r; 14 | 15 | public: 16 | node() 17 | { 18 | pa = l = r = nullptr; 19 | } 20 | node *getPa() { return pa; } 21 | node *getLeft() { return l; } 22 | node *getRight() { return r; } 23 | void setPa(node *temp) 24 | { 25 | pa = temp; 26 | } 27 | void setR(node *temp) 28 | { 29 | r = temp; 30 | } 31 | void setL(node *temp) 32 | { 33 | l = temp; 34 | } 35 | bool has_L() { return l != nullptr; } 36 | bool has_r() { return r != nullptr; } 37 | void setE(T temp) 38 | { 39 | elem = temp; 40 | } 41 | T getE() { return elem; } 42 | void set_Key(key temp) 43 | { 44 | k = temp; 45 | } 46 | key get_K() { return k; } 47 | }; 48 | #endif -------------------------------------------------------------------------------- /Vector/TestVector.cpp: -------------------------------------------------------------------------------- 1 | #include"myvector.cpp" 2 | #include"bits/stdc++.h" 3 | using namespace std; 4 | int main() 5 | { 6 | myVector V(7,6); 7 | cout<<"\nVector ban dau:"; 8 | for(int i=0;i::iterator it=V.begin();it!=V.end();++it) 28 | cout<<*it<<"\t"; 29 | 30 | cout<<"\nDuyet auto : "; 31 | for(auto x:V) 32 | cout< Q; 34 | Q=V; 35 | cout<<"\nDuyet auto Q: "; 36 | for(auto x:Q) 37 | cout<::reverse_iterator it=Q.rbegin();it!=Q.rend();++it) 44 | cout<<*it<<" "; 45 | } 46 | -------------------------------------------------------------------------------- /btvn_/danh_ba/test.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "vector_moi.cpp" 3 | using namespace std; 4 | int main() 5 | { 6 | int c[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 0}; 7 | vector_moi a(c, c + 10); 8 | a.bo_o_cuoi(); 9 | for (int i = 0; i < a.sophantu(); i++) 10 | { 11 | cout << a[i] << " "; 12 | } 13 | cout << endl; 14 | a.chen(2, 10); 15 | for (int i = 0; i < a.sophantu(); i++) 16 | { 17 | cout << a[i] << " "; 18 | } 19 | a.xoa(2,5); 20 | cout << endl; 21 | for (int i = 0; i < a.sophantu(); i++) 22 | { 23 | cout << a[i] << " "; 24 | } 25 | a.them_cuoi(100); 26 | cout << endl; 27 | for (int i = 0; i < a.sophantu(); i++) 28 | { 29 | cout << a[i] << " "; 30 | } 31 | vector_moi b(c, c+10); 32 | a.hoan_doi(b); 33 | cout << endl; 34 | for (int i = 0; i < a.sophantu(); i++) 35 | { 36 | cout << a[i] << " "; 37 | } 38 | cout << endl; 39 | for (int i = 0; i < b.sophantu(); i++) 40 | { 41 | cout << b[i] << " "; 42 | } 43 | a.giai_phong(); 44 | cout< 2 | #include "vector_moi.cpp" 3 | using namespace std; 4 | int main() 5 | { 6 | int c[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 0}; 7 | vector_moi a(c, c + 10); 8 | a.bo_o_cuoi(); 9 | for (int i = 0; i < a.sophantu(); i++) 10 | { 11 | cout << a[i] << " "; 12 | } 13 | cout << endl; 14 | a.chen(2, 10); 15 | for (int i = 0; i < a.sophantu(); i++) 16 | { 17 | cout << a[i] << " "; 18 | } 19 | a.xoa(2,5); 20 | cout << endl; 21 | for (int i = 0; i < a.sophantu(); i++) 22 | { 23 | cout << a[i] << " "; 24 | } 25 | a.them_cuoi(100); 26 | cout << endl; 27 | for (int i = 0; i < a.sophantu(); i++) 28 | { 29 | cout << a[i] << " "; 30 | } 31 | vector_moi b(c, c+10); 32 | a.hoan_doi(b); 33 | cout << endl; 34 | for (int i = 0; i < a.sophantu(); i++) 35 | { 36 | cout << a[i] << " "; 37 | } 38 | cout << endl; 39 | for (int i = 0; i < b.sophantu(); i++) 40 | { 41 | cout << b[i] << " "; 42 | } 43 | a.giai_phong(); 44 | cout< 2 | #ifndef _lien_he_cpp 3 | #define _lien_he_cpp 4 | using namespace std; 5 | class contact 6 | { 7 | string name, email, number; 8 | 9 | public: 10 | contact() {} 11 | contact(string name, string email, string number) 12 | { 13 | this->email = email; 14 | this->name = name; 15 | this->number = number; 16 | } 17 | friend istream &operator>>(istream &cin, contact &a) 18 | { 19 | cin.ignore(1); 20 | cout << "Nhap lien he moi:\n"; 21 | cout << "\tHo ten: "; 22 | getline(cin, a.name); 23 | cout << "\tSo dien thoai: "; 24 | cin >> a.number; 25 | cout << "\tEmail: "; 26 | cin >> a.email; 27 | return cin; 28 | } 29 | friend ostream &operator<<(ostream &cout, const contact a) 30 | { 31 | cout << "\tHo ten: " << a.name << endl; 32 | cout << "\tSo dien thoai: " << a.number << endl; 33 | cout << "\tEmail: " << a.email << endl; 34 | return cout; 35 | } 36 | string name_contact() { return name; } 37 | string number_phone() { return number; } 38 | string email_contact() { return email; } 39 | }; 40 | #endif 41 | -------------------------------------------------------------------------------- /ung_dung_tree/mytree.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #ifndef _tree_hi_hi 3 | #define _tree_hi_hi 4 | using namespace std; 5 | template 6 | class node 7 | { 8 | T value; 9 | int n = 0, _l = 0, _r = 0; 10 | node *left = nullptr; 11 | node *right = nullptr; 12 | 13 | public: 14 | node() {} 15 | node(T x) 16 | { 17 | value = x; 18 | n = 1; 19 | } 20 | void push(T x) 21 | { 22 | if (n == 0) 23 | value = x; 24 | else if (x < value) 25 | { 26 | _l++; 27 | if (left == nullptr) 28 | left = new node(x); 29 | else 30 | left->push(x); 31 | } 32 | else if (x > value) 33 | { 34 | _r++; 35 | if (right == nullptr) 36 | right = new node(x); 37 | else right->push(x); 38 | } 39 | n++; 40 | } 41 | int size() { return n; } 42 | void print() 43 | { 44 | if (left != nullptr) 45 | left->print(); 46 | int temp = n - _l - _r; 47 | for (int i = 0; i < temp; i++) 48 | cout << value << " "; 49 | if (right != nullptr) 50 | right->print(); 51 | } 52 | }; 53 | #endif -------------------------------------------------------------------------------- /ung_dung_queue/queue_moi.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #ifndef _queue_cpp 3 | #define _queue_cpp 4 | using namespace std; 5 | template 6 | class queue_moi 7 | { 8 | int n, cap, f, l; 9 | T *a; 10 | 11 | protected: 12 | void extend() 13 | { 14 | cap = cap ? cap * 2 : 1; 15 | T *temp = new T[cap]; 16 | for (int i = f, j = 0; i < f + n; i++, j++) 17 | temp[j] = a[i % n]; 18 | f = 0; 19 | l = n; 20 | delete[] a; 21 | a = temp; 22 | } 23 | 24 | public: 25 | queue_moi() 26 | { 27 | n = cap = f = l = 0; 28 | a = nullptr; 29 | } 30 | ~queue_moi() 31 | { 32 | delete[] a; 33 | } 34 | bool empty() { return n == 0; } 35 | int size() { return n; } 36 | void pop() 37 | { 38 | if (n > 0) 39 | { 40 | n--; 41 | f = ++f % cap; 42 | if (!n) 43 | f = l = 0; 44 | } 45 | } 46 | 47 | void push(T x) 48 | { 49 | if (n == cap) 50 | { 51 | extend(); 52 | } 53 | a[l % cap] = x; 54 | l = l >= cap ? l % cap : ++l; 55 | n++; 56 | } 57 | T &front() { return a[f]; } 58 | T &back() 59 | { 60 | if (l == 0) 61 | return a[cap - 1]; 62 | return a[l - 1]; 63 | } 64 | }; 65 | #endif -------------------------------------------------------------------------------- /BSTree/DemoSV.cpp: -------------------------------------------------------------------------------- 1 | #include "conio.h" 2 | #include "Btree.cpp" 3 | #include "iostream" 4 | using namespace std; 5 | class Student 6 | { 7 | private: 8 | int masv; 9 | char hodem[30]; 10 | char ten[10]; 11 | char gioi[4]; 12 | public: 13 | int getMaSV(){ return masv;} 14 | char* getHodem(){ return hodem;} 15 | char* getTen(){ return ten;} 16 | char* getGioi(){ return gioi;} 17 | friend istream & operator >>(istream &is, Student &s); 18 | friend ostream & operator <<(ostream &os, Student s); 19 | }; 20 | istream & operator >>(istream &is, Student &s) 21 | { 22 | cout<<"\nNhap ma sv:"; 23 | is>>s.masv; 24 | cout<<"Nhap ho dem:"; 25 | is.ignore(1); 26 | is.get(s.hodem,30); 27 | cout<<"Nhap ten:"; 28 | is.ignore(1); 29 | is.get(s.ten,10); 30 | cout<<"Nhap gioi tinh:"; 31 | is.ignore(1); 32 | is.get(s.gioi,4); 33 | return is; 34 | } 35 | ostream & operator <<(ostream &os, Student s) 36 | { 37 | os<*p) 42 | { 43 | cout<<"\n"<getKey()<<","<< p->getElem(); 44 | } 45 | 46 | int main(){ 47 | BTree tree; 48 | Student s; 49 | for(int i=0;i<3;i++) 50 | { 51 | cout<<"Nhap sinh vien thu:"<>s; 53 | tree.insert(s.getMaSV(), s); 54 | } 55 | tree.preOrder(tree.getRoot(),v); 56 | } 57 | 58 | 59 | -------------------------------------------------------------------------------- /BSTree/DEMO.CPP: -------------------------------------------------------------------------------- 1 | #include "conio.h" 2 | #include "Btree.cpp" 3 | #include "iostream" 4 | using namespace std; 5 | void v(BNode*p) 6 | { 7 | cout<<"("<getKey()<<","<< p->getElem()<<")"; 8 | } 9 | 10 | int main(){ 11 | BTree tree; 12 | BNode *p; 13 | //BNode *p; 14 | system("cls"); 15 | tree.insert(100,"100-1"); 16 | tree.insert(80,"80a"); 17 | tree.insert(25,"25x"); 18 | tree.insert(105,"105"); 19 | tree.insert(13,"13"); 20 | tree.insert(120,"120"); 21 | tree.insert(175,"175"); 22 | tree.insert(30,"30x"); 23 | tree.insert(46,"46"); 24 | //tree.preOrder(tree.getRoot(),visit); 25 | cout<<"\nDuyet cay theo thu tu giua:"; 26 | tree.inOrder(tree.getRoot(),v); 27 | 28 | tree.remove(25); 29 | cout<<"\n"; 30 | cout<<"\nDuyet cay theo thu tu giua:"; 31 | tree.inOrder(tree.getRoot(),v); 32 | // cout<<"\n"; 33 | // tree.postOrder(tree.getRoot(),v); 34 | //tree.remove(150); 35 | cout<<"\n"; 36 | //tree.inOrder(tree.getRoot(),visit); 37 | /*p = tree.search(120, tree.getRoot()); 38 | if(p!=NULL) 39 | cout<<"Tim thay khoa 120, Co gia tri "<getElem(); 40 | else 41 | cout<<"Khong tim thay khoa 120."; 42 | 43 | tree.remove(120); 44 | //tree.remove(100); 45 | tree.remove(70); 46 | cout<<"\nDuyet cay theo thu tu giua:"; 47 | tree.inOrder(tree.getRoot(),visit);*/ 48 | getch(); 49 | return 0; 50 | } 51 | 52 | -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "C_Cpp_Runner.cCompilerPath": "gcc", 3 | "C_Cpp_Runner.cppCompilerPath": "g++", 4 | "C_Cpp_Runner.debuggerPath": "gdb", 5 | "C_Cpp_Runner.cStandard": "", 6 | "C_Cpp_Runner.cppStandard": "", 7 | "C_Cpp_Runner.msvcBatchPath": "", 8 | "C_Cpp_Runner.useMsvc": false, 9 | "C_Cpp_Runner.warnings": [ 10 | "-Wall", 11 | "-Wextra", 12 | "-Wpedantic", 13 | "-Wshadow", 14 | "-Wformat=2", 15 | "-Wcast-align", 16 | "-Wconversion", 17 | "-Wsign-conversion", 18 | "-Wnull-dereference" 19 | ], 20 | "C_Cpp_Runner.msvcWarnings": [ 21 | "/W4", 22 | "/permissive-", 23 | "/w14242", 24 | "/w14287", 25 | "/w14296", 26 | "/w14311", 27 | "/w14826", 28 | "/w44062", 29 | "/w44242", 30 | "/w14905", 31 | "/w14906", 32 | "/w14263", 33 | "/w44265", 34 | "/w14928" 35 | ], 36 | "C_Cpp_Runner.enableWarnings": true, 37 | "C_Cpp_Runner.warningsAsError": false, 38 | "C_Cpp_Runner.compilerArgs": [], 39 | "C_Cpp_Runner.linkerArgs": [], 40 | "C_Cpp_Runner.includePaths": [], 41 | "C_Cpp_Runner.includeSearch": [ 42 | "*", 43 | "**/*" 44 | ], 45 | "C_Cpp_Runner.excludeSearch": [ 46 | "**/build", 47 | "**/build/**", 48 | "**/.*", 49 | "**/.*/**", 50 | "**/.vscode", 51 | "**/.vscode/**" 52 | ], 53 | "C_Cpp_Runner.useAddressSanitizer": false, 54 | "C_Cpp_Runner.useUndefinedSanitizer": false, 55 | "C_Cpp_Runner.useLeakSanitizer": false, 56 | "C_Cpp_Runner.showCompilationTime": false, 57 | "C_Cpp_Runner.useLinkTimeOptimization": false, 58 | "C_Cpp_Runner.msvcSecureNoWarnings": false 59 | } -------------------------------------------------------------------------------- /btvn_/.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "C_Cpp_Runner.cCompilerPath": "gcc", 3 | "C_Cpp_Runner.cppCompilerPath": "g++", 4 | "C_Cpp_Runner.debuggerPath": "gdb", 5 | "C_Cpp_Runner.cStandard": "", 6 | "C_Cpp_Runner.cppStandard": "", 7 | "C_Cpp_Runner.msvcBatchPath": "", 8 | "C_Cpp_Runner.useMsvc": false, 9 | "C_Cpp_Runner.warnings": [ 10 | "-Wall", 11 | "-Wextra", 12 | "-Wpedantic", 13 | "-Wshadow", 14 | "-Wformat=2", 15 | "-Wcast-align", 16 | "-Wconversion", 17 | "-Wsign-conversion", 18 | "-Wnull-dereference" 19 | ], 20 | "C_Cpp_Runner.msvcWarnings": [ 21 | "/W4", 22 | "/permissive-", 23 | "/w14242", 24 | "/w14287", 25 | "/w14296", 26 | "/w14311", 27 | "/w14826", 28 | "/w44062", 29 | "/w44242", 30 | "/w14905", 31 | "/w14906", 32 | "/w14263", 33 | "/w44265", 34 | "/w14928" 35 | ], 36 | "C_Cpp_Runner.enableWarnings": true, 37 | "C_Cpp_Runner.warningsAsError": false, 38 | "C_Cpp_Runner.compilerArgs": [], 39 | "C_Cpp_Runner.linkerArgs": [], 40 | "C_Cpp_Runner.includePaths": [], 41 | "C_Cpp_Runner.includeSearch": [ 42 | "*", 43 | "**/*" 44 | ], 45 | "C_Cpp_Runner.excludeSearch": [ 46 | "**/build", 47 | "**/build/**", 48 | "**/.*", 49 | "**/.*/**", 50 | "**/.vscode", 51 | "**/.vscode/**" 52 | ], 53 | "C_Cpp_Runner.useAddressSanitizer": false, 54 | "C_Cpp_Runner.useUndefinedSanitizer": false, 55 | "C_Cpp_Runner.useLeakSanitizer": false, 56 | "C_Cpp_Runner.showCompilationTime": false, 57 | "C_Cpp_Runner.useLinkTimeOptimization": false, 58 | "C_Cpp_Runner.msvcSecureNoWarnings": false 59 | } -------------------------------------------------------------------------------- /ung_dung_vector/.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "C_Cpp_Runner.cCompilerPath": "gcc", 3 | "C_Cpp_Runner.cppCompilerPath": "g++", 4 | "C_Cpp_Runner.debuggerPath": "gdb", 5 | "C_Cpp_Runner.cStandard": "", 6 | "C_Cpp_Runner.cppStandard": "", 7 | "C_Cpp_Runner.msvcBatchPath": "", 8 | "C_Cpp_Runner.useMsvc": false, 9 | "C_Cpp_Runner.warnings": [ 10 | "-Wall", 11 | "-Wextra", 12 | "-Wpedantic", 13 | "-Wshadow", 14 | "-Wformat=2", 15 | "-Wcast-align", 16 | "-Wconversion", 17 | "-Wsign-conversion", 18 | "-Wnull-dereference" 19 | ], 20 | "C_Cpp_Runner.msvcWarnings": [ 21 | "/W4", 22 | "/permissive-", 23 | "/w14242", 24 | "/w14287", 25 | "/w14296", 26 | "/w14311", 27 | "/w14826", 28 | "/w44062", 29 | "/w44242", 30 | "/w14905", 31 | "/w14906", 32 | "/w14263", 33 | "/w44265", 34 | "/w14928" 35 | ], 36 | "C_Cpp_Runner.enableWarnings": true, 37 | "C_Cpp_Runner.warningsAsError": false, 38 | "C_Cpp_Runner.compilerArgs": [], 39 | "C_Cpp_Runner.linkerArgs": [], 40 | "C_Cpp_Runner.includePaths": [], 41 | "C_Cpp_Runner.includeSearch": [ 42 | "*", 43 | "**/*" 44 | ], 45 | "C_Cpp_Runner.excludeSearch": [ 46 | "**/build", 47 | "**/build/**", 48 | "**/.*", 49 | "**/.*/**", 50 | "**/.vscode", 51 | "**/.vscode/**" 52 | ], 53 | "C_Cpp_Runner.useAddressSanitizer": false, 54 | "C_Cpp_Runner.useUndefinedSanitizer": false, 55 | "C_Cpp_Runner.useLeakSanitizer": false, 56 | "C_Cpp_Runner.showCompilationTime": false, 57 | "C_Cpp_Runner.useLinkTimeOptimization": false, 58 | "C_Cpp_Runner.msvcSecureNoWarnings": false 59 | } -------------------------------------------------------------------------------- /btvn_/APP_QUAN_LY_TAI_LIEU/.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "C_Cpp_Runner.cCompilerPath": "gcc", 3 | "C_Cpp_Runner.cppCompilerPath": "g++", 4 | "C_Cpp_Runner.debuggerPath": "gdb", 5 | "C_Cpp_Runner.cStandard": "", 6 | "C_Cpp_Runner.cppStandard": "", 7 | "C_Cpp_Runner.msvcBatchPath": "", 8 | "C_Cpp_Runner.useMsvc": false, 9 | "C_Cpp_Runner.warnings": [ 10 | "-Wall", 11 | "-Wextra", 12 | "-Wpedantic", 13 | "-Wshadow", 14 | "-Wformat=2", 15 | "-Wcast-align", 16 | "-Wconversion", 17 | "-Wsign-conversion", 18 | "-Wnull-dereference" 19 | ], 20 | "C_Cpp_Runner.msvcWarnings": [ 21 | "/W4", 22 | "/permissive-", 23 | "/w14242", 24 | "/w14287", 25 | "/w14296", 26 | "/w14311", 27 | "/w14826", 28 | "/w44062", 29 | "/w44242", 30 | "/w14905", 31 | "/w14906", 32 | "/w14263", 33 | "/w44265", 34 | "/w14928" 35 | ], 36 | "C_Cpp_Runner.enableWarnings": true, 37 | "C_Cpp_Runner.warningsAsError": false, 38 | "C_Cpp_Runner.compilerArgs": [], 39 | "C_Cpp_Runner.linkerArgs": [], 40 | "C_Cpp_Runner.includePaths": [], 41 | "C_Cpp_Runner.includeSearch": [ 42 | "*", 43 | "**/*" 44 | ], 45 | "C_Cpp_Runner.excludeSearch": [ 46 | "**/build", 47 | "**/build/**", 48 | "**/.*", 49 | "**/.*/**", 50 | "**/.vscode", 51 | "**/.vscode/**" 52 | ], 53 | "C_Cpp_Runner.useAddressSanitizer": false, 54 | "C_Cpp_Runner.useUndefinedSanitizer": false, 55 | "C_Cpp_Runner.useLeakSanitizer": false, 56 | "C_Cpp_Runner.showCompilationTime": false, 57 | "C_Cpp_Runner.useLinkTimeOptimization": false, 58 | "C_Cpp_Runner.msvcSecureNoWarnings": false 59 | } -------------------------------------------------------------------------------- /btvn_/APP_QUAN_LY_TAI_LIEU/document.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #ifndef _tai_lieu_cpp 3 | #define _tai_lieu_cpp 4 | using namespace std; 5 | class document 6 | { 7 | string name, description, writer, format; 8 | int year; 9 | 10 | public: 11 | document() {} 12 | document(string name, string description, string writer, string format, int year) 13 | { 14 | this->name = name; 15 | this->description = description; 16 | this->writer = writer; 17 | this->format = format; 18 | this->year = year; 19 | } 20 | friend istream &operator>>(istream &cin, document &a) 21 | { 22 | cin.ignore(1); 23 | cout << "\tTen tai lieu: "; 24 | getline(cin, a.name); 25 | cout << "\tMo ta: "; 26 | getline(cin, a.description); 27 | cout << "\tTac gia: "; 28 | getline(cin, a.writer); 29 | cout << "\tDinh dang: "; 30 | cin >> a.format; 31 | cout << "\tNam xuat ban: "; 32 | cin >> a.year; 33 | return cin; 34 | } 35 | friend ostream &operator<<(ostream &cout, const document a) 36 | { 37 | cout << "\tTen tai lieu: " << a.name << endl; 38 | cout << "\tMo ta: " << a.description << endl; 39 | cout << "\tTac gia: " << a.writer << endl; 40 | cout << "\tDinh dang: " << a.format << endl; 41 | cout << "\tNam xuat ban: " << a.year << endl; 42 | return cout; 43 | } 44 | string name_doc() { return name; } 45 | string descrip_doc() { return description; } 46 | string writer_doc() { return writer; } 47 | string format_doc() { return format; } 48 | int year_doc() { return year; } 49 | }; 50 | #endif -------------------------------------------------------------------------------- /Vector/.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "C_Cpp_Runner.cCompilerPath": "gcc", 3 | "C_Cpp_Runner.cppCompilerPath": "g++", 4 | "C_Cpp_Runner.debuggerPath": "gdb", 5 | "C_Cpp_Runner.cStandard": "", 6 | "C_Cpp_Runner.cppStandard": "", 7 | "C_Cpp_Runner.msvcBatchPath": "", 8 | "C_Cpp_Runner.useMsvc": false, 9 | "C_Cpp_Runner.warnings": [ 10 | "-Wall", 11 | "-Wextra", 12 | "-Wpedantic", 13 | "-Wshadow", 14 | "-Wformat=2", 15 | "-Wcast-align", 16 | "-Wconversion", 17 | "-Wsign-conversion", 18 | "-Wnull-dereference" 19 | ], 20 | "C_Cpp_Runner.msvcWarnings": [ 21 | "/W4", 22 | "/permissive-", 23 | "/w14242", 24 | "/w14287", 25 | "/w14296", 26 | "/w14311", 27 | "/w14826", 28 | "/w44062", 29 | "/w44242", 30 | "/w14905", 31 | "/w14906", 32 | "/w14263", 33 | "/w44265", 34 | "/w14928" 35 | ], 36 | "C_Cpp_Runner.enableWarnings": true, 37 | "C_Cpp_Runner.warningsAsError": false, 38 | "C_Cpp_Runner.compilerArgs": [], 39 | "C_Cpp_Runner.linkerArgs": [], 40 | "C_Cpp_Runner.includePaths": [], 41 | "C_Cpp_Runner.includeSearch": [ 42 | "*", 43 | "**/*" 44 | ], 45 | "C_Cpp_Runner.excludeSearch": [ 46 | "**/build", 47 | "**/build/**", 48 | "**/.*", 49 | "**/.*/**", 50 | "**/.vscode", 51 | "**/.vscode/**" 52 | ], 53 | "C_Cpp_Runner.useAddressSanitizer": false, 54 | "C_Cpp_Runner.useUndefinedSanitizer": false, 55 | "C_Cpp_Runner.useLeakSanitizer": false, 56 | "C_Cpp_Runner.showCompilationTime": false, 57 | "C_Cpp_Runner.useLinkTimeOptimization": false, 58 | "files.associations": { 59 | "array": "cpp", 60 | "bitset": "cpp", 61 | "string_view": "cpp", 62 | "initializer_list": "cpp", 63 | "regex": "cpp", 64 | "utility": "cpp", 65 | "valarray": "cpp" 66 | }, 67 | "C_Cpp_Runner.msvcSecureNoWarnings": false 68 | } -------------------------------------------------------------------------------- /ung_dung_linked_list/linked_list.cpp: -------------------------------------------------------------------------------- 1 | #include "node_iterator.cpp" 2 | #ifndef _linked_list_CPP 3 | #define _linked_list_CPP 4 | using namespace std; 5 | template 6 | class Don_list 7 | { 8 | node *head, *end; 9 | int num; 10 | 11 | public: 12 | Don_list() 13 | { 14 | head = end = nullptr; 15 | num = 0; 16 | } 17 | int size() { return num; } 18 | bool empty() { return num == 0; } 19 | T &front() { return head->getE(); } 20 | T &back() { return end->getE(); } 21 | void push_front(T x) 22 | { 23 | node *temp = new node; 24 | temp->setNext(head); 25 | temp->setE(x); 26 | head = temp; 27 | if (!num) 28 | end = temp; 29 | num++; 30 | } 31 | void insert(node *p, T x) 32 | { 33 | if (!num) 34 | push_front(x); 35 | else 36 | { 37 | node *temp = new node; 38 | temp->setNext(p->getNext()); 39 | p->setNext(temp); 40 | temp->setE(x); 41 | if (end == p) 42 | end = temp; 43 | num++; 44 | } 45 | } 46 | void push_back(T x) 47 | { 48 | insert(cuoi().getnode(),x); 49 | } 50 | void erase_head() 51 | { 52 | if (!num) 53 | return; 54 | if (num == 1) 55 | { 56 | head = end = nullptr; 57 | return; 58 | } 59 | node *temp = new node; 60 | temp = head->getNext(); 61 | head = temp; 62 | num--; 63 | } 64 | void erase(node *p) 65 | { 66 | node *temp = p->getNext(); 67 | p = temp->getNext(); 68 | num--; 69 | } 70 | void pop_front() 71 | { 72 | erase_head(); 73 | } 74 | void pop_back() 75 | { 76 | if (num < 2) 77 | erase_head(); 78 | else 79 | { 80 | node *temp = new node; 81 | while (temp->getNext() != end) 82 | { 83 | temp++; 84 | } 85 | erase(temp); 86 | } 87 | } 88 | iter dau() { return head; } 89 | iter cuoi() { return end; } 90 | }; 91 | #endif -------------------------------------------------------------------------------- /BTL_2023/linkedlist/linked_list.cpp: -------------------------------------------------------------------------------- 1 | #include "node_iterator.cpp" 2 | #ifndef _linked_list_CPP 3 | #define _linked_list_CPP 4 | using namespace std; 5 | template 6 | class Don_list 7 | { 8 | node *head, *end; 9 | int num; 10 | 11 | public: 12 | Don_list() 13 | { 14 | head = end = nullptr; 15 | num = 0; 16 | } 17 | ~Don_list(){ 18 | delete head; 19 | delete end; 20 | } 21 | int size() { return num; } 22 | bool empty() { return num == 0; } 23 | T &front() { return head->getE(); } 24 | T &back() { return end->getE(); } 25 | iter dau() { return head; } 26 | iter cuoi() { return end; } 27 | void push_front(T x) 28 | { 29 | node *temp = new node; 30 | temp->setNext(head); 31 | temp->setE(x); 32 | head = temp; 33 | if (!num) 34 | end = temp; 35 | num++; 36 | } 37 | void insert(node *p, T x) 38 | { 39 | if (!num) 40 | push_front(x); 41 | else 42 | { 43 | node *temp = new node; 44 | temp->setNext(p->getNext()); 45 | p->setNext(temp); 46 | temp->setE(x); 47 | if (end == p) 48 | end = temp; 49 | num++; 50 | } 51 | } 52 | void push_back(T x) 53 | { 54 | insert(cuoi().getnode(),x); 55 | } 56 | void erase_head() 57 | { 58 | if (!num) 59 | return; 60 | if (num == 1) 61 | { 62 | head = end = nullptr; 63 | return; 64 | } 65 | node *temp = new node; 66 | temp = head->getNext(); 67 | head = temp; 68 | num--; 69 | } 70 | void erase(node *p) 71 | { 72 | node *temp = p->getNext(); 73 | p = temp->getNext(); 74 | num--; 75 | } 76 | void pop_front() 77 | { 78 | erase_head(); 79 | } 80 | void pop_back() 81 | { 82 | if (num < 2) 83 | erase_head(); 84 | else 85 | { 86 | node *temp = new node; 87 | while (temp->getNext() != end) 88 | { 89 | temp++; 90 | } 91 | erase(temp); 92 | } 93 | } 94 | }; 95 | #endif -------------------------------------------------------------------------------- /btvn_/danh_ba/App_Contact.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "addressbook.cpp" 3 | using namespace std; 4 | class app 5 | { 6 | AddressBook a; 7 | 8 | public: 9 | void home() 10 | { 11 | cout << "\n _______________^-^_______________\n"; 12 | cout << " | Danh ba |\n"; 13 | cout << " | |\n"; 14 | cout << " | 1. Xem danh ba. |\n"; 15 | cout << " | 2. Them lien he moi. |\n"; 16 | cout << " | 3. Xoa lien he. |\n"; 17 | cout << " | 4. Tim kiem lien he. |\n"; 18 | cout << " | 5. Thoat chuong trinh. |\n"; 19 | cout << " | |\n"; 20 | cout << " ---------------------------------\n"; 21 | cout << "\nChon tac vu ban muon thuc hien: "; 22 | int x; 23 | cin >> x; 24 | cout << "\n"; 25 | switch (x) 26 | { 27 | case 1: 28 | show(); 29 | break; 30 | case 2: 31 | a.add_contact(); 32 | break; 33 | case 3: 34 | a.erase(); 35 | break; 36 | case 4: 37 | a.search(); 38 | break; 39 | case 5: 40 | cout << " Nhac lai!!\n"; 41 | return; 42 | default: 43 | cout << "Thao tac khong dung!\n"; 44 | } 45 | home(); 46 | } 47 | bool continue_app() 48 | { 49 | cout << "\nBan co muon thoat chuong trinh?\n"; 50 | cout << "Nhap \"y\" de xac nhan hoac \"n\" de huy: "; 51 | char x; 52 | cin >> x; 53 | if (x == 'y') 54 | return true; 55 | else 56 | return false; 57 | } 58 | void show() 59 | { 60 | cout << "----------------------------------\n"; 61 | if (a.size() == 0) 62 | cout << " Danh ba trong!\n"; 63 | else 64 | a.list_contact(); 65 | cout << "----------------------------------\n"; 66 | cout << "\nNhap phim bat ky de quay lai: "; 67 | char x; 68 | cin >> x; 69 | } 70 | void run() 71 | { 72 | do 73 | { 74 | home(); 75 | } while (!continue_app()); 76 | } 77 | void end_task() 78 | { 79 | cout << "\t __ __" << endl; 80 | cout << "\t ******** ********" << endl; 81 | cout << "\t****____________****" << endl; 82 | cout << "\t****| Goodbye! |***" << endl; 83 | cout << "\t ***------------**" << endl; 84 | cout << "\t *************" << endl; 85 | cout << "\t *******" << endl; 86 | cout << "\t *" << endl; 87 | } 88 | }; -------------------------------------------------------------------------------- /BTL_2023/graph/linked_list.cpp: -------------------------------------------------------------------------------- 1 | #include "node_iterator.cpp" 2 | #ifndef _linked_list_CPP 3 | #define _linked_list_CPP 4 | using namespace std; 5 | template 6 | class Don_list 7 | { 8 | node *head, *tail; 9 | int num; 10 | 11 | public: 12 | Don_list() 13 | { 14 | head = tail = nullptr; 15 | num = 0; 16 | } 17 | int size() { return num; } 18 | bool empty() { return num == 0; } 19 | T &front() { return head->getE(); } 20 | T &back() { return tail->getE(); } 21 | Don_list &operator = (const Don_list&x){ 22 | head = new node; 23 | head = x.head; 24 | num= x.num; 25 | tail = new node; 26 | tail= x.tail; 27 | return *this; 28 | } 29 | void push_front(T x) 30 | { 31 | node *temp = new node; 32 | temp->setNext(head); 33 | temp->setE(x); 34 | head = temp; 35 | if (!num) 36 | tail = temp; 37 | num++; 38 | } 39 | void insert(node *p, T x) 40 | { 41 | if (!num) 42 | push_front(x); 43 | else 44 | { 45 | node *temp = new node; 46 | temp->setNext(p->getNext()); 47 | p->setNext(temp); 48 | temp->setE(x); 49 | if (tail == p) 50 | tail = temp; 51 | num++; 52 | } 53 | } 54 | void push_back(T x) 55 | { 56 | insert(cuoi().getnode(), x); 57 | } 58 | void erase_head() 59 | { 60 | if (!num) 61 | return; 62 | if (num == 1) 63 | { 64 | delete head; 65 | head = tail = nullptr; 66 | return; 67 | } 68 | node *temp = new node; 69 | temp = head->getNext(); 70 | head = temp; 71 | delete temp; 72 | num--; 73 | } 74 | void erase(node *p) 75 | { 76 | if (!num) 77 | return; 78 | if (p == nullptr) 79 | return; 80 | node *temp = p->getNext(); 81 | p->setNext(temp->getNext()); 82 | delete temp; 83 | num--; 84 | } 85 | void pop_front() 86 | { 87 | erase_head(); 88 | } 89 | void pop_back() 90 | { 91 | if (num < 2) 92 | erase_head(); 93 | else 94 | { 95 | node *temp = new node; 96 | temp = head; 97 | while (temp->getNext() != tail) 98 | { 99 | temp = temp->getNext(); 100 | } 101 | erase(temp); 102 | tail=temp; 103 | } 104 | } 105 | iter dau() { return head; } 106 | iter cuoi() { return tail; } 107 | }; 108 | #endif -------------------------------------------------------------------------------- /Vector/myvector.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #ifndef __vector__cpp__ 3 | #define __vector__cpp__ 4 | using namespace std; 5 | template 6 | class myvector_reverse_iterator 7 | { 8 | T *curr; 9 | public: 10 | myvector_reverse_iterator(T *c=0) {curr=c;} 11 | myvector_reverse_iterator &operator=(myvector_reverse_iterator it) 12 | { 13 | this->curr=it.curr; 14 | return *this; 15 | } 16 | myvector_reverse_iterator operator++()//++curr 17 | { 18 | curr--; 19 | return curr; 20 | } 21 | myvector_reverse_iterator operator++(int)//++curr 22 | { 23 | myvector_reverse_iterator tmp=curr; 24 | curr--; 25 | return tmp; 26 | } 27 | T &operator*() {return *curr;} 28 | bool operator!=(myvector_reverse_iterator t) {return curr!=t.curr;} 29 | }; 30 | 31 | template 32 | class myvector 33 | { 34 | private: 35 | int cap,num; 36 | T *buff; 37 | public: 38 | myvector() { 39 | cap=1; 40 | num=0; 41 | buff=new T[1]; 42 | } 43 | myvector(int k,T x) { 44 | cap=num=k; 45 | buff=new T[k]; 46 | for(int i=0;i0) num--;} 54 | void extend(int newcap) 55 | { 56 | if(newcap=k;i--) 76 | buff[i+1]=buff[i]; 77 | buff[k]=x; 78 | num++; 79 | } 80 | void erase(int k) 81 | { 82 | if (k<0 || k>size()) 83 | return; 84 | for(;k V) 89 | { 90 | this->num=V.num; 91 | this->cap=V.cap; 92 | if(cap) 93 | { 94 | this->buff=new T[cap]; 95 | for(int i=0;ibuff[i]=V.buff[i]; 96 | } 97 | else this->buff=0; 98 | return *this; 99 | } 100 | typedef T *iterator; 101 | iterator begin() {return buff;} 102 | iterator end() {return buff+num;} 103 | typedef myvector_reverse_iterator reverse_iterator; 104 | reverse_iterator rbegin() 105 | { 106 | return reverse_iterator(buff+num-1); 107 | } 108 | reverse_iterator rend() 109 | { 110 | return reverse_iterator(buff-1); 111 | } 112 | 113 | }; 114 | #endif 115 | 116 | -------------------------------------------------------------------------------- /Vector/stuApp.cpp: -------------------------------------------------------------------------------- 1 | #include "conio.h" 2 | #include "stdio.h" 3 | #include "iostream" 4 | #include "myvector.cpp" 5 | #include "student.cpp" 6 | using namespace std; 7 | class VectorApp // Lop ung dung lop vector va lop VectorItr 8 | { 9 | private: 10 | myvector v; 11 | 12 | public: 13 | int menu(); 14 | void run(); 15 | void GetElement(); 16 | void InsertElement(); 17 | void RemoveElement(); 18 | void ReplaceElement(); 19 | void ListElement(); 20 | }; 21 | int VectorApp::menu() 22 | { 23 | cout << "1.Them mot sinh vien moi"; 24 | cout << "\n2.Xoa mot sinh vien"; 25 | cout << "\n3.Thay the mot sinh vien"; 26 | cout << "\n4. Lay thong tin mot sinh vien"; 27 | cout << "\n5.In danh sach sinh vien"; 28 | cout << "\n6.Ket thuc chuong trinh"; 29 | cout << "\nChon chuc nang tu 1..6:"; 30 | int n; 31 | cin >> n; 32 | return n; 33 | } 34 | void VectorApp::run() 35 | { 36 | int ch; 37 | do 38 | { 39 | system("cls"); 40 | ch = menu(); 41 | system("cls"); 42 | switch (ch) 43 | { 44 | case 1: 45 | InsertElement(); 46 | break; 47 | case 2: 48 | RemoveElement(); 49 | break; 50 | case 3: 51 | ReplaceElement(); 52 | break; 53 | case 4: 54 | GetElement(); 55 | break; 56 | case 5: 57 | ListElement(); 58 | break; 59 | } 60 | getch(); 61 | } while (ch != 6); 62 | } 63 | void VectorApp::InsertElement() 64 | { 65 | Student x; 66 | int r; 67 | cout << "Nhap thong tin cua sinh vien:"; 68 | cin >> x; 69 | cout << "Vi tri chen:"; 70 | cin >> r; 71 | v.insert(r, x); 72 | cout << "Chen phan tu thanh cong!"; 73 | } 74 | void VectorApp::RemoveElement() 75 | { 76 | myvector::iterator it; 77 | int ma; 78 | cout << "Nhap ma cua sinh vien can xoa bo:"; 79 | cin >> ma; 80 | int k = 0; 81 | bool found = false; 82 | while (k < v.size() && found == false) 83 | if (v[k].getmasv() == ma) 84 | found = true; 85 | else 86 | k++; 87 | if (found) 88 | { 89 | v.erase(k); 90 | cout << "Phan tu bi xoa di :" << v[k]; 91 | } 92 | else 93 | cout << "Khong tim thay sinh vien can xoa"; 94 | } 95 | void VectorApp::ReplaceElement() 96 | { 97 | int ma; 98 | Student x; 99 | cout << "Nhap ma cua sinh vien can thay the:"; 100 | cin >> ma; 101 | int k = 0; 102 | bool found = false; 103 | while (k < v.size() && found == false) 104 | if (v[k].getmasv() == ma) 105 | found = true; 106 | else 107 | k++; 108 | if (found) 109 | { 110 | cout << "Nhap thong tin can thay the:"; 111 | cin >> x; 112 | v[k] = x; 113 | } 114 | else 115 | cout << "Khong tim thay sinh vien co ma " << ma; 116 | } 117 | void VectorApp::GetElement() 118 | { 119 | myvector::iterator it; 120 | int ma; 121 | cout << "Nhap ma cua sinh vien :"; 122 | cin >> ma; 123 | int k = 0; 124 | bool found = false; 125 | while (k < v.size() && found == false) 126 | if (v[k].getmasv() == ma) 127 | found = true; 128 | else 129 | k++; 130 | if (found) 131 | { 132 | cout << "Thong tin sinh vien :" << v[k]; 133 | } 134 | else 135 | cout << "Khong tim thay sinh vien"; 136 | } 137 | void VectorApp::ListElement() 138 | { 139 | myvector::iterator it; 140 | cout << "Danh sach cac sinh vien:\n"; 141 | it = v.begin(); 142 | while (it != v.end()) 143 | { 144 | cout << *it; 145 | it++; 146 | } 147 | } 148 | -------------------------------------------------------------------------------- /Vector/vtor.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #ifndef __vector__cpp__ 3 | #define __vector__cpp__ 4 | using namespace std; 5 | template 6 | class myvector_reverse_iterator 7 | { 8 | T *curr; 9 | public: 10 | myvector_reverse_iterator(T *c=0) {curr=c;} 11 | myvector_reverse_iterator &operator=(myvector_reverse_iterator it) 12 | { 13 | this->curr=it.curr; 14 | return *this; 15 | } 16 | myvector_reverse_iterator operator++()//++curr 17 | { 18 | curr--; 19 | return curr; 20 | } 21 | myvector_reverse_iterator operator++(int)//++curr 22 | { 23 | myvector_reverse_iterator tmp=curr; 24 | curr--; 25 | return tmp; 26 | } 27 | T &operator*() {return *curr;} 28 | bool operator!=(myvector_reverse_iterator t) {return curr!=t.curr;} 29 | }; 30 | 31 | template 32 | class myvector 33 | { 34 | private: 35 | int cap,num; 36 | T *buff; 37 | public: 38 | myvector() { 39 | cap=1; 40 | num=0; 41 | buff=0; 42 | } 43 | myvector(int k,T x) { 44 | cap=num=k; 45 | buff=new T[k]; 46 | for(int i=0;i0) num--;} 54 | void extend(int newcap) 55 | { 56 | if(newcap=k;i--) 76 | buff[i+1]=buff[i]; 77 | buff[k]=x; 78 | num++; 79 | } 80 | void erase(int k) 81 | { 82 | if (k<0 || k>size()) 83 | return; 84 | for(;k V) 89 | { 90 | this->num=V.num; 91 | this->cap=V.cap; 92 | if(cap) 93 | { 94 | this->buff=new T[cap]; 95 | for(int i=0;ibuff[i]=V.buff[i]; 96 | } 97 | else this->buff=0; 98 | return *this; 99 | } 100 | typedef T *iterator; 101 | iterator begin() {return buff;} 102 | iterator end() {return buff+num;} 103 | typedef myvector_reverse_iterator reverse_iterator; 104 | reverse_iterator rbegin() 105 | { 106 | return reverse_iterator(buff+num-1); 107 | } 108 | reverse_iterator rend() 109 | { 110 | return reverse_iterator(buff-1); 111 | } 112 | 113 | }; 114 | #endif 115 | 116 | int main() 117 | { 118 | myvector V(7,6); 119 | cout<<"\nmyvector ban dau:"; 120 | for(int i=0;i::iterator it=V.begin();it!=V.end();it++) 132 | cout<<*it<<"\t"; 133 | cout<<"\nDuyet auto : "; 134 | for(auto x:V) 135 | cout< 2 | #ifndef vector_moi_C 3 | #define vector_moi_C 4 | using namespace std; 5 | template 6 | class vector_moi 7 | { 8 | int n, so_phan_tu_max; 9 | T *a; 10 | 11 | public: 12 | bool rong() 13 | { 14 | return n == 0; 15 | } 16 | int ptu_max() 17 | { 18 | return so_phan_tu_max; 19 | } 20 | int sophantu() 21 | { 22 | return n; 23 | } 24 | vector_moi() 25 | { 26 | so_phan_tu_max = 1; 27 | n = 0; 28 | a = new T[1]; 29 | } 30 | vector_moi(int k, T temp) 31 | { 32 | so_phan_tu_max = n = k; 33 | a = new T[k]; 34 | for (int i = 0; i < n; i++) 35 | a[i] = temp; 36 | } 37 | vector_moi(T *arr, T *arr_cuoi) 38 | { 39 | so_phan_tu_max = n = arr_cuoi - arr; 40 | a = new T[n]; 41 | for (int i = 0; i < n; i++) 42 | a[i] = arr[i]; 43 | } 44 | void bo_o_cuoi() 45 | { 46 | if (n > 0) 47 | n--; 48 | } 49 | void morong(int cap) 50 | { 51 | if (so_phan_tu_max < cap) 52 | so_phan_tu_max = cap; 53 | else 54 | return; 55 | T *temp = new T[so_phan_tu_max]; 56 | for (int i = 0; i < n; i++) 57 | temp[i] = a[i]; 58 | delete[] a; 59 | a = temp; 60 | } 61 | void chen(int vitri, T giatri) 62 | { 63 | if (so_phan_tu_max == n) 64 | morong(2 * n); 65 | for (int i = n - 1; i >= vitri; i--) 66 | a[i + 1] = a[i]; 67 | a[vitri] = giatri; 68 | n++; 69 | } 70 | void xoa(int vitri) 71 | { 72 | for (int i = vitri; i < n - 1; i++) 73 | a[i] = a[i + 1]; 74 | n--; 75 | } 76 | void xoa(int dau, int cuoi) 77 | { 78 | T *temp = new T[so_phan_tu_max]; 79 | int i = 0, j = 0; 80 | while (i < n && j < n) 81 | { 82 | if (i == dau) 83 | j = cuoi + 1; 84 | temp[i] = a[j]; 85 | i++; 86 | j++; 87 | } 88 | delete[] a; 89 | a = temp; 90 | n = i; 91 | } 92 | T &operator[](int k) 93 | { 94 | return a[k]; 95 | } 96 | void doi_kick_thuoc(int newsize) 97 | { 98 | T *temp = new T[newsize]; 99 | if (newsize < n) 100 | { 101 | for (int i = 0; i < newsize; i++) 102 | temp[i] = a[i]; 103 | n = newsize; 104 | } 105 | else 106 | for (int i = 0; i < n; i++) 107 | temp[i] = a[i]; 108 | } 109 | void doi_kick_thuoc(int newsize, int giatri) 110 | { 111 | T *temp = new T[newsize]; 112 | if (newsize < n) 113 | for (int i = 0; i < newsize; i++) 114 | temp[i] = a[i]; 115 | else 116 | { 117 | for (int i = 0; i < n; i++) 118 | temp[i] = a[i]; 119 | for (int i = n + 1; i < newsize; i++) 120 | temp[i] = giatri; 121 | } 122 | n = newsize; 123 | } 124 | void them_cuoi(T x) 125 | { 126 | if (so_phan_tu_max == n) 127 | morong(2 * n); 128 | a[n] = x; 129 | n++; 130 | } 131 | void hoan_doi(vector_moi &b) 132 | { 133 | int sptm, cnt; 134 | if (b.so_phan_tu_max > so_phan_tu_max) 135 | n = sptm = b.so_phan_tu_max; 136 | else 137 | sptm = so_phan_tu_max = b.so_phan_tu_max; 138 | T *temp = new T[sptm]; 139 | temp = a; 140 | cnt = n; 141 | a = b.a; 142 | n = b.sophantu(); 143 | b.a = temp; 144 | b.n = cnt; 145 | } 146 | void giai_phong(){ 147 | so_phan_tu_max = 1; 148 | n = 0; 149 | a = new T[1]; 150 | } 151 | void themchen(int vitri, T giatri){ 152 | chen(vitri, giatri); 153 | } 154 | void themchen_cuoi(T giatri){ 155 | them_cuoi(giatri); 156 | } 157 | }; 158 | #endif -------------------------------------------------------------------------------- /btvn_/danh_ba/vector_moi.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #ifndef vector_moi_C 3 | #define vector_moi_C 4 | using namespace std; 5 | template 6 | class vector_moi 7 | { 8 | int n, so_phan_tu_max; 9 | T *a; 10 | 11 | public: 12 | bool rong() 13 | { 14 | return n == 0; 15 | } 16 | int ptu_max() 17 | { 18 | return so_phan_tu_max; 19 | } 20 | int sophantu() 21 | { 22 | return n; 23 | } 24 | vector_moi() 25 | { 26 | so_phan_tu_max = 1; 27 | n = 0; 28 | a = new T[1]; 29 | } 30 | vector_moi(int k, T temp) 31 | { 32 | so_phan_tu_max = n = k; 33 | a = new T[k]; 34 | for (int i = 0; i < n; i++) 35 | a[i] = temp; 36 | } 37 | vector_moi(T *arr, T *arr_cuoi) 38 | { 39 | so_phan_tu_max = n = arr_cuoi - arr; 40 | a = new T[n]; 41 | for (int i = 0; i < n; i++) 42 | a[i] = arr[i]; 43 | } 44 | void bo_o_cuoi() 45 | { 46 | if (n > 0) 47 | n--; 48 | } 49 | void morong(int cap) 50 | { 51 | if (so_phan_tu_max < cap) 52 | so_phan_tu_max = cap; 53 | else 54 | return; 55 | T *temp = new T[so_phan_tu_max]; 56 | for (int i = 0; i < n; i++) 57 | temp[i] = a[i]; 58 | delete[] a; 59 | a = temp; 60 | } 61 | void chen(int vitri, T giatri) 62 | { 63 | if (so_phan_tu_max == n) 64 | morong(2 * n); 65 | for (int i = n - 1; i >= vitri; i--) 66 | a[i + 1] = a[i]; 67 | a[vitri] = giatri; 68 | n++; 69 | } 70 | void xoa(int vitri) 71 | { 72 | for (int i = vitri; i < n - 1; i++) 73 | a[i] = a[i + 1]; 74 | n--; 75 | } 76 | void xoa(int dau, int cuoi) 77 | { 78 | T *temp = new T[so_phan_tu_max]; 79 | int i = 0, j = 0; 80 | while (i < n && j < n) 81 | { 82 | if (i == dau) 83 | j = cuoi + 1; 84 | temp[i] = a[j]; 85 | i++; 86 | j++; 87 | } 88 | delete[] a; 89 | a = temp; 90 | n = i; 91 | } 92 | T &operator[](int k) 93 | { 94 | return a[k]; 95 | } 96 | void doi_kick_thuoc(int newsize) 97 | { 98 | T *temp = new T[newsize]; 99 | if (newsize < n) 100 | { 101 | for (int i = 0; i < newsize; i++) 102 | temp[i] = a[i]; 103 | n = newsize; 104 | } 105 | else 106 | for (int i = 0; i < n; i++) 107 | temp[i] = a[i]; 108 | } 109 | void doi_kick_thuoc(int newsize, int giatri) 110 | { 111 | T *temp = new T[newsize]; 112 | if (newsize < n) 113 | for (int i = 0; i < newsize; i++) 114 | temp[i] = a[i]; 115 | else 116 | { 117 | for (int i = 0; i < n; i++) 118 | temp[i] = a[i]; 119 | for (int i = n + 1; i < newsize; i++) 120 | temp[i] = giatri; 121 | } 122 | n = newsize; 123 | } 124 | void them_cuoi(T x) 125 | { 126 | if (so_phan_tu_max == n) 127 | morong(2 * n); 128 | a[n] = x; 129 | n++; 130 | } 131 | void hoan_doi(vector_moi &b) 132 | { 133 | int sptm, cnt; 134 | if (b.so_phan_tu_max > so_phan_tu_max) 135 | n = sptm = b.so_phan_tu_max; 136 | else 137 | sptm = so_phan_tu_max = b.so_phan_tu_max; 138 | T *temp = new T[sptm]; 139 | temp = a; 140 | cnt = n; 141 | a = b.a; 142 | n = b.sophantu(); 143 | b.a = temp; 144 | b.n = cnt; 145 | } 146 | void giai_phong() 147 | { 148 | so_phan_tu_max = 1; 149 | n = 0; 150 | a = new T[1]; 151 | } 152 | void themchen(int vitri, T giatri) 153 | { 154 | chen(vitri, giatri); 155 | } 156 | void themchen_cuoi(T giatri) 157 | { 158 | them_cuoi(giatri); 159 | } 160 | }; 161 | #endif -------------------------------------------------------------------------------- /btvn_/APP_QUAN_LY_TAI_LIEU/app_manager.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "user.cpp" 3 | #ifndef _app_cpp 4 | #define _app_cpp 5 | using namespace std; 6 | class app 7 | { 8 | vector_moi a; 9 | 10 | public: 11 | friend istream &operator>>(istream &cin, app &b) 12 | { 13 | user x; 14 | cin >> x; 15 | b.a.them_cuoi(x); 16 | return cin; 17 | } 18 | void access_user() 19 | { 20 | cout << "\n___________________________________________\n"; 21 | cout << "| DANH SACH NGUOI DUNG |\n"; 22 | if (a.sophantu() == 0) 23 | { 24 | cout << "|\t____________________________ |\n"; 25 | cout << "|\t| Khong co nguoi dung nao! | |\n"; 26 | cout << "|\t---------------------------- |\n"; 27 | } 28 | else 29 | { 30 | cout << "|\t____________________________ |\n"; 31 | for (int i = 0; i < a.sophantu(); i++) 32 | { 33 | cout << "|\t|" << i + 1 << ". " << left << setw(22) << a[i].name_user() << " | |" << endl; 34 | } 35 | cout << "|\t---------------------------- |\n"; 36 | } 37 | int cnt = 0; 38 | cout << "|\t |\n"; 39 | cout << "|\t____________________________ |\n"; 40 | if (a.sophantu()) 41 | { 42 | cnt++; 43 | cout << "|\t|" << cnt << ". Truy cap nguoi dung. | |\n"; 44 | } 45 | cout << "|\t|" << cnt + 1 << ". Them nguoi dung moi. | |\n"; 46 | cout << "|\t|" << cnt + 2 << ". Thoat. | |\n"; 47 | cout << "-------------------------------------------\n"; 48 | cout << " \tChon tac vu:"; 49 | int n; 50 | cin >> n; 51 | cout << "-------------------------------------------\n"; 52 | if (n == cnt + 2) 53 | return; 54 | if (cnt) 55 | { 56 | switch (n) 57 | { 58 | case 1: 59 | { 60 | cout << "Truy cap nguoi dung thu: "; 61 | int k; 62 | cin >> k; 63 | if (k < 1 || k > a.sophantu()) 64 | cout << "So nguoi dung khong hop le!\n"; 65 | else 66 | a[k - 1].home_user(); 67 | break; 68 | } 69 | case 2: 70 | { 71 | user x; 72 | cin >> x; 73 | a.them_cuoi(x); 74 | cout << "\nNhap phim bat ky de quay lai: "; 75 | char y; 76 | cin >> y; 77 | break; 78 | } 79 | } 80 | if (n != 1 && n != 2) 81 | cout << "So tac vu khong hop le!\n"; 82 | } 83 | else 84 | { 85 | switch (n) 86 | { 87 | case 1: 88 | user x; 89 | cin >> x; 90 | a.them_cuoi(x); 91 | cout << "\nNhap phim bat ky de quay lai: "; 92 | char y; 93 | cin >> y; 94 | break; 95 | } 96 | if (n != 1) 97 | cout << "So tac vu khong hop le!\n"; 98 | } 99 | access_user(); 100 | } 101 | bool out(){ 102 | user a; 103 | if(a.out()) return true; 104 | return false; 105 | } 106 | void home() 107 | { 108 | do 109 | { 110 | access_user(); 111 | } while (!out()); 112 | } 113 | void end_task() 114 | { 115 | cout << "\t __ __" << endl; 116 | cout << "\t ******** ********" << endl; 117 | cout << "\t****____________****" << endl; 118 | cout << "\t****| Goodbye! |***" << endl; 119 | cout << "\t ***------------**" << endl; 120 | cout << "\t *************" << endl; 121 | cout << "\t *******" << endl; 122 | cout << "\t *" << endl; 123 | } 124 | }; 125 | #endif -------------------------------------------------------------------------------- /btvn_/APP_QUAN_LY_TAI_LIEU/vector_moi.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #ifndef vector_moi_C 3 | #define vector_moi_C 4 | using namespace std; 5 | template 6 | class vector_moi 7 | { 8 | int n, so_phan_tu_max; 9 | T *a; 10 | 11 | public: 12 | bool rong() 13 | { 14 | return n == 0; 15 | } 16 | int ptu_max() 17 | { 18 | return so_phan_tu_max; 19 | } 20 | int sophantu() 21 | { 22 | return n; 23 | } 24 | vector_moi() 25 | { 26 | so_phan_tu_max = 1; 27 | n = 0; 28 | a = new T[1]; 29 | } 30 | vector_moi(int k, T temp) 31 | { 32 | so_phan_tu_max = n = k; 33 | a = new T[k]; 34 | for (int i = 0; i < n; i++) 35 | a[i] = temp; 36 | } 37 | vector_moi(T *arr, T *arr_cuoi) 38 | { 39 | so_phan_tu_max = n = arr_cuoi - arr; 40 | a = new T[n]; 41 | for (int i = 0; i < n; i++) 42 | a[i] = arr[i]; 43 | } 44 | void bo_o_cuoi() 45 | { 46 | if (n > 0) 47 | n--; 48 | } 49 | void morong(int cap) 50 | { 51 | if (so_phan_tu_max < cap) 52 | so_phan_tu_max = cap; 53 | else 54 | return; 55 | T *temp = new T[so_phan_tu_max]; 56 | for (int i = 0; i < n; i++) 57 | temp[i] = a[i]; 58 | delete[] a; 59 | a = temp; 60 | } 61 | void chen(int vitri, T giatri) 62 | { 63 | if (so_phan_tu_max == n) 64 | morong(2 * n); 65 | for (int i = n - 1; i >= vitri; i--) 66 | a[i + 1] = a[i]; 67 | a[vitri] = giatri; 68 | n++; 69 | } 70 | void xoa(int vitri) 71 | { 72 | for (int i = vitri; i < n - 1; i++) 73 | a[i] = a[i + 1]; 74 | n--; 75 | } 76 | void xoa(int dau, int cuoi) 77 | { 78 | T *temp = new T[so_phan_tu_max]; 79 | int i = 0, j = 0; 80 | while (i < n && j < n) 81 | { 82 | if (i == dau) 83 | j = cuoi + 1; 84 | temp[i] = a[j]; 85 | i++; 86 | j++; 87 | } 88 | delete[] a; 89 | a = temp; 90 | n = i; 91 | } 92 | T &operator[](int k) 93 | { 94 | return a[k]; 95 | } 96 | void doi_kick_thuoc(int newsize) 97 | { 98 | T *temp = new T[newsize]; 99 | if (newsize < n) 100 | { 101 | for (int i = 0; i < newsize; i++) 102 | temp[i] = a[i]; 103 | n = newsize; 104 | } 105 | else 106 | for (int i = 0; i < n; i++) 107 | temp[i] = a[i]; 108 | } 109 | void doi_kick_thuoc(int newsize, int giatri) 110 | { 111 | T *temp = new T[newsize]; 112 | if (newsize < n) 113 | for (int i = 0; i < newsize; i++) 114 | temp[i] = a[i]; 115 | else 116 | { 117 | for (int i = 0; i < n; i++) 118 | temp[i] = a[i]; 119 | for (int i = n + 1; i < newsize; i++) 120 | temp[i] = giatri; 121 | } 122 | n = newsize; 123 | } 124 | void them_cuoi(T x) 125 | { 126 | if (so_phan_tu_max == n) 127 | morong(2 * n); 128 | a[n] = x; 129 | n++; 130 | } 131 | void hoan_doi(vector_moi &b) 132 | { 133 | int sptm, cnt; 134 | if (b.so_phan_tu_max > so_phan_tu_max) 135 | n = sptm = b.so_phan_tu_max; 136 | else 137 | sptm = so_phan_tu_max = b.so_phan_tu_max; 138 | T *temp = new T[sptm]; 139 | temp = a; 140 | cnt = n; 141 | a = b.a; 142 | n = b.sophantu(); 143 | b.a = temp; 144 | b.n = cnt; 145 | } 146 | void giai_phong() 147 | { 148 | so_phan_tu_max = 1; 149 | n = 0; 150 | a = new T[1]; 151 | } 152 | void themchen(int vitri, T giatri) 153 | { 154 | chen(vitri, giatri); 155 | } 156 | void themchen_cuoi(T giatri) 157 | { 158 | them_cuoi(giatri); 159 | } 160 | }; 161 | #endif -------------------------------------------------------------------------------- /BTL_2023/linkedlist/can_bo.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #ifndef _can_bo_cpp 3 | #define _can_bo_cpp 4 | using namespace std; 5 | 6 | int _cmp(string s, string t) 7 | { 8 | int len1 = s.length(), len2 = t.length(); 9 | int min_len = len1 < len2 ? len1 : len2; 10 | for (int i = 0; i < min_len; i++) 11 | { 12 | if (tolower(s[i]) != tolower(t[i])) 13 | { 14 | return tolower(s[i]) - tolower(t[i]); 15 | } 16 | } 17 | if (len1 < len2) 18 | return '\0' - t[min_len]; 19 | else if (len1 > len2) 20 | return s[min_len] - '\0'; 21 | else 22 | return 0; 23 | } 24 | class can_bo 25 | { 26 | int id; 27 | string ho, ten, ban, cvu; 28 | float hsl; 29 | long long luong; 30 | void tinh_luong() 31 | { 32 | luong = hsl * 1350000; 33 | } 34 | 35 | public: 36 | can_bo(int id = 0, string ho = "", string ten = "", string ban = "", string cvu = "", float hsl = 0) 37 | { 38 | this->id = id; 39 | this->ho = ho; 40 | this->ten = ten; 41 | this->ban = ban; 42 | this->cvu = cvu; 43 | this->hsl = hsl; 44 | tinh_luong(); 45 | } 46 | can_bo(const can_bo &x) 47 | { 48 | this->id = x.id; 49 | this->ho = x.ho; 50 | this->ten = x.ten; 51 | this->ban = x.ban; 52 | this->cvu = x.cvu; 53 | this->hsl = x.hsl; 54 | tinh_luong(); 55 | } 56 | can_bo &operator=(const can_bo &x) 57 | { 58 | this->id = x.id; 59 | this->ho = x.ho; 60 | this->ten = x.ten; 61 | this->ban = x.ban; 62 | this->cvu = x.cvu; 63 | this->hsl = x.hsl; 64 | tinh_luong(); 65 | return *this; 66 | } 67 | bool operator==(can_bo x) 68 | { 69 | if (id == x.id && !_cmp(ho_ten(), x.ho_ten()) && !_cmp(ban, x.ban) && !_cmp(cvu, x.cvu) && hsl == x.hsl) 70 | return true; 71 | return false; 72 | } 73 | bool input() 74 | { 75 | cout << "\tNhap ma can bo: "; 76 | cin >> id; 77 | if (id <= 0) 78 | return false; 79 | cin.ignore(1); 80 | cout << "\tNhap ho ten can bo: "; 81 | string temp; 82 | getline(cin, temp); 83 | bool test = false; 84 | for (int i = temp.length() - 1; i >= 0; i--) 85 | { 86 | if (temp[i] == ' ') 87 | { 88 | ho = temp.substr(0, i); 89 | ten = temp.substr(i + 1, temp.length() - i); 90 | test = true; 91 | break; 92 | } 93 | if (!test) 94 | { 95 | ten = temp; 96 | ho = ""; 97 | } 98 | } 99 | cout << "\tPhong ban: "; 100 | getline(cin, ban); 101 | cout << "\tChuc vu: "; 102 | getline(cin, cvu); 103 | cout << "\tHe so luong: "; 104 | cin >> hsl; 105 | tinh_luong(); 106 | return true; 107 | } 108 | friend istream &operator>>(istream &cin, can_bo &x) 109 | { 110 | cout << "\tNhap ma can bo: "; 111 | cin >> x.id; 112 | cin.ignore(1); 113 | cout << "\tNhap ho ten can bo: "; 114 | string temp; 115 | getline(cin, temp); 116 | bool test = false; 117 | for (int i = temp.length() - 1; i >= 0; i--) 118 | { 119 | if (temp[i] == ' ') 120 | { 121 | x.ho = temp.substr(0, i); 122 | x.ten = temp.substr(i + 1, temp.length() - i); 123 | test = true; 124 | break; 125 | } 126 | if (!test) 127 | { 128 | x.ten = temp; 129 | x.ho = ""; 130 | } 131 | } 132 | cout << "\tPhong ban: "; 133 | getline(cin, x.ban); 134 | cout << "\tChuc vu: "; 135 | getline(cin, x.cvu); 136 | cout << "\tHe so luong: "; 137 | cin >> x.hsl; 138 | x.tinh_luong(); 139 | return cin; 140 | } 141 | friend ostream &operator<<(ostream &cout, const can_bo &x) 142 | { 143 | cout << "\tMa can bo: " << x.id << endl; 144 | cout << "\tHo ten can bo: " << x.ho << " " << x.ten << endl; 145 | cout << "\tPhong ban: " << x.ban << endl; 146 | cout << "\tChuc vu: " << x.cvu << endl; 147 | cout << "\tHe so luong: " << x.hsl << endl; 148 | cout << "\tLuong: " << x.luong << endl; 149 | return cout; 150 | } 151 | int ma_can_bo() { return id; } 152 | string ho_ten() 153 | { 154 | string temp = ho + " " + ten; 155 | return temp; 156 | } 157 | string Ho() { return ho; } 158 | string Ten() { return ten; } 159 | string phong_ban() { return ban; } 160 | string chuc_vu() { return cvu; } 161 | float he_so_luong() { return hsl; } 162 | long long Luong() { return luong; } 163 | }; 164 | #endif -------------------------------------------------------------------------------- /btvn_/APP_QUAN_LY_TAI_LIEU/user.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "folder.cpp" 3 | #ifndef _user_cpp 4 | #define _user_cpp 5 | using namespace std; 6 | class user 7 | { 8 | string name; 9 | vector_moi a; 10 | 11 | public: 12 | friend istream &operator>>(istream &cin, user &b) 13 | { 14 | cout << "Ten nguoi dung moi: "; 15 | cin.ignore(1); 16 | getline(cin, b.name); 17 | cout << "\t\nThem nguoi dung thanh cong!\n"; 18 | return cin; 19 | } 20 | void erase_folder() 21 | { 22 | cout << "Ten thu muc muon xoa: "; 23 | string x; 24 | bool cnt = false; 25 | cin.ignore(1); 26 | getline(cin, x); 27 | for (int i = 0; i < a.sophantu(); i++) 28 | { 29 | if (x == a[i].name_folder()) 30 | { 31 | a.xoa(i); 32 | cnt = true; 33 | } 34 | } 35 | if (cnt) 36 | cout << "Xoa thanh cong!\n"; 37 | else 38 | cout << "Khong tim thay thu muc can xoa\n"; 39 | } 40 | bool out() 41 | { 42 | folder a; 43 | if (a.out()) 44 | return true; 45 | return false; 46 | } 47 | string name_user() { return name; } 48 | int spt() { return a.sophantu(); } 49 | void access_folder() 50 | { 51 | cout << "\n___________________________________________\n"; 52 | cout << "| DANH SACH THU MUC |\n"; 53 | if (a.sophantu() == 0) 54 | { 55 | cout << "|\t____________________________ |\n"; 56 | cout << "|\t| Khong co thu muc nao! | |\n"; 57 | cout << "|\t---------------------------- |\n"; 58 | } 59 | else 60 | { 61 | cout << "|\t____________________________ |\n"; 62 | for (int i = 0; i < a.sophantu(); i++) 63 | { 64 | cout << "|\t|" << i + 1 << ". " << left << setw(22) << a[i].name_folder() << " | |" << endl; 65 | } 66 | cout << "|\t---------------------------- |\n"; 67 | } 68 | int cnt = 0; 69 | cout << "|\t |\n"; 70 | cout << "|\t____________________________ |\n"; 71 | if (a.sophantu()) 72 | { 73 | cnt++; 74 | cout << "|\t|" << cnt << ". Truy cap thu muc. | |\n"; 75 | } 76 | cout << "|\t|" << cnt + 1 << ". Tao thu muc moi. | |\n"; 77 | cout << "|\t|" << cnt + 2 << ". Xoa thu muc. | |\n"; 78 | cout << "|\t|" << cnt + 3 << ". Quay lai. | |\n"; 79 | cout << "-------------------------------------------\n"; 80 | cout << " \tChon tac vu:"; 81 | int n; 82 | cin >> n; 83 | cout << "-------------------------------------------\n"; 84 | if (n == cnt + 3) 85 | return; 86 | if (cnt) 87 | { 88 | switch (n) 89 | { 90 | case 1: 91 | { 92 | cout << "Truy cap thu muc thu: "; 93 | int k; 94 | cin >> k; 95 | if (k < 1 || k > a.sophantu()) 96 | cout << "So thu muc khong hop le!\n"; 97 | else 98 | a[k - 1].home_folder(); 99 | break; 100 | } 101 | case 2: 102 | { 103 | folder x; 104 | cin >> x; 105 | a.them_cuoi(x); 106 | cout << "\tTao thu muc thanh cong!\n"; 107 | cout << "\nNhap phim bat ky de quay lai: "; 108 | char y; 109 | cin >> y; 110 | break; 111 | } 112 | case 3: 113 | { 114 | erase_folder(); 115 | cout << "\nNhap phim bat ky de quay lai: "; 116 | char y; 117 | cin >> y; 118 | break; 119 | } 120 | default: 121 | { 122 | cout << "So tac vu khong hop le!\n"; 123 | break; 124 | } 125 | } 126 | } 127 | else 128 | { 129 | switch (n) 130 | { 131 | case 1: 132 | { 133 | folder x; 134 | cin >> x; 135 | a.them_cuoi(x); 136 | cout << "\tTao thu muc thanh cong!\n"; 137 | cout << "\nNhap phim bat ky de quay lai: "; 138 | char y; 139 | cin >> y; 140 | break; 141 | } 142 | default: 143 | cout << "So tac vu khong hop le!\n"; 144 | break; 145 | } 146 | } 147 | access_folder(); 148 | } 149 | void home_user() 150 | { 151 | do 152 | { 153 | access_folder(); 154 | } while (!out()); 155 | return; 156 | } 157 | }; 158 | #endif -------------------------------------------------------------------------------- /btvn_/APP_QUAN_LY_TAI_LIEU/folder.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "vector_moi.cpp" 3 | #include "document.cpp" 4 | #ifndef _thu_muc_cpp 5 | #define _thu_muc_cpp 6 | using namespace std; 7 | class folder 8 | { 9 | string name; 10 | bool temp = true; 11 | vector_moi a; 12 | 13 | public: 14 | friend istream &operator>>(istream &cin, folder &b) 15 | { 16 | cout << "Ten thu muc moi: "; 17 | cin.ignore(1); 18 | getline(cin, b.name); 19 | return cin; 20 | } 21 | friend ostream &operator<<(ostream &cout, folder &b) 22 | { 23 | if (b.a.sophantu() == 0) 24 | { 25 | cout << "Thu muc trong\n"; 26 | } 27 | else 28 | { 29 | for (int i = 0; i < b.a.sophantu(); i++) 30 | { 31 | cout << i + 1 << ". " << b.a[i].name_doc() << endl; 32 | } 33 | } 34 | return cout; 35 | } 36 | void erase_doc() 37 | { 38 | cout << "Ten tai lieu muon xoa: "; 39 | string x; 40 | bool cnt = false; 41 | cin.ignore(1); 42 | getline(cin, x); 43 | for (int i = 0; i < a.sophantu(); i++) 44 | { 45 | if (x == a[i].name_doc()) 46 | { 47 | a.xoa(i); 48 | cnt = true; 49 | } 50 | } 51 | if (cnt) 52 | cout << "Xoa thanh cong!\n"; 53 | else 54 | cout << "Khong tim thay tai lieu can xoa\n"; 55 | } 56 | bool out(){ 57 | cout << "\n___________________________________________\n"; 58 | cout << "\nBan muon thoat chuong trinh?\n"; 59 | cout << "Nhap \"y\" de xac nhan, \"n\" de tu choi: "; 60 | char x; 61 | cin >> x; 62 | cout << "-------------------------------------------\n"; 63 | if (x == 'y') 64 | return true; 65 | else 66 | return false; 67 | } 68 | string name_folder() { return name; } 69 | void access_doc() 70 | { 71 | cout << "\n___________________________________________\n"; 72 | cout << "| DANH SACH THU MUC |\n"; 73 | if (a.sophantu() == 0) 74 | { 75 | cout << "|\t____________________________ |\n"; 76 | cout << "|\t| Thu muc trong! | |\n"; 77 | cout << "|\t---------------------------- |\n"; 78 | } 79 | else 80 | { 81 | cout << "|\t____________________________ |\n"; 82 | for (int i = 0; i < a.sophantu(); i++) 83 | { 84 | cout << "|\t|" << i + 1 << ". " << left << setw(22) << a[i].name_doc() << " | |" << endl; 85 | } 86 | cout << "|\t---------------------------- |\n"; 87 | } 88 | int cnt = 0; 89 | cout << "|\t |\n"; 90 | cout << "|\t____________________________ |\n"; 91 | if (a.sophantu()) 92 | { 93 | cnt++; 94 | cout << "|\t|" << cnt << ". Truy cap tai lieu . | |\n"; 95 | } 96 | cout << "|\t|" << cnt + 1 << ". Tao tai lieu moi. | |\n"; 97 | cout << "|\t|" << cnt + 2 << ". Xoa tai lieu. | |\n"; 98 | cout << "|\t|" << cnt + 3 << ". Quay lai. | |\n"; 99 | cout << "-------------------------------------------\n"; 100 | cout << " \tChon tac vu:"; 101 | int n; 102 | cin >> n; 103 | cout << "-------------------------------------------\n"; 104 | if (n == cnt + 3) 105 | return; 106 | if (cnt) 107 | { 108 | switch (n) 109 | { 110 | case 1: 111 | { 112 | cout << "Truy cap tai lieu thu: "; 113 | int k; 114 | cin >> k; 115 | if (k < 1 || k > a.sophantu()) 116 | { 117 | cout << "So tai lieu khong hop le!\n"; 118 | } 119 | else 120 | { 121 | cout << a[k - 1]; 122 | } 123 | cout << "\nNhap phim bat ky de quay lai: "; 124 | char y; 125 | cin >> y; 126 | break; 127 | } 128 | case 2: 129 | { 130 | document x; 131 | cin >> x; 132 | a.them_cuoi(x); 133 | cout << "\tTao tai lieu thanh cong!\n"; 134 | cout << "\nNhap phim bat ky de quay lai: "; 135 | char y; 136 | cin >> y; 137 | break; 138 | } 139 | case 3: 140 | erase_doc(); 141 | cout << "\nNhap phim bat ky de quay lai: "; 142 | char y; 143 | cin >> y; 144 | break; 145 | default: 146 | cout << "So tac vu khong hop le!\n"; 147 | break; 148 | } 149 | cout << "\nNhap phim bat ky de quay lai: "; 150 | char y; 151 | cin >> y; 152 | } 153 | else 154 | { 155 | switch (n) 156 | { 157 | case 1: 158 | { 159 | document x; 160 | cin >> x; 161 | a.them_cuoi(x); 162 | cout << "\tTao tai lieu thanh cong!\n"; 163 | cout << "\nNhap phim bat ky de quay lai: "; 164 | char y; 165 | cin >> y; 166 | break; 167 | } 168 | default: 169 | cout << "So tac vu khong hop le!\n"; 170 | break; 171 | } 172 | cout << "\nNhap phim bat ky de quay lai: "; 173 | char y; 174 | cin >> y; 175 | } 176 | access_doc(); 177 | } 178 | void home_folder() 179 | { 180 | do 181 | { 182 | access_doc(); 183 | } while (!out()); 184 | return; 185 | } 186 | }; 187 | #endif -------------------------------------------------------------------------------- /btvn_/danh_ba/addressbook.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "contact.cpp" 3 | #include "vector_moi.cpp" 4 | #ifndef _danh_ba_cpp 5 | #define _danh_ba_cpp 6 | using namespace std; 7 | int cmp(const void *a, const void *b) 8 | { 9 | contact *x = (contact *)a; 10 | contact *y = (contact *)b; 11 | return x->name_contact() < y->name_contact(); 12 | } 13 | class AddressBook 14 | { 15 | vector_moi a; 16 | 17 | public: 18 | void add_contact() 19 | { 20 | cout << "----------------------------------\n"; 21 | cout << "Them lien he moi:\n"; 22 | cout << "\t1. Nhap 1 lien he.\n"; 23 | cout << "\t2. Nhap nhieu lien he.\n"; 24 | cout << "\t3. Quay lai.\n"; 25 | int cnt; 26 | cout << "\t"; 27 | cin >> cnt; 28 | switch (cnt) 29 | { 30 | case 1: 31 | { 32 | contact x; 33 | cin >> x; 34 | a.them_cuoi(x); 35 | break; 36 | } 37 | case 2: 38 | { 39 | int n; 40 | cout << "Nhap so lien he them moi: "; 41 | cin >> n; 42 | for (int i = 0; i < n; i++) 43 | { 44 | contact x; 45 | cin >> x; 46 | a.them_cuoi(x); 47 | } 48 | break; 49 | } 50 | case 3: 51 | return; 52 | default: 53 | cout << "\nThao tac khong hop le!\n\n"; 54 | break; 55 | } 56 | cout << "\nNhap thanh cong!\n\n"; 57 | cout << "----------------------------------\n"; 58 | cout << "\nNhap phim bat ky de quay lai: "; 59 | char y; 60 | cin >> y; 61 | } 62 | void erase() 63 | { 64 | cout << "----------------------------------\n"; 65 | cout << "Xoa lien he theo:\n"; 66 | cout << "\t1. Ho ten.\n"; 67 | cout << "\t2. So dien thoai.\n"; 68 | cout << "\t3. Email.\n"; 69 | int cnt; 70 | cout << "\t"; 71 | cin >> cnt; 72 | switch (cnt) 73 | { 74 | case 1: 75 | { 76 | cout << "Nhap ho ten lien he can xoa: "; 77 | string x; 78 | cin.ignore(1); 79 | getline(cin, x); 80 | bool temp = false; 81 | for (int i = 0; i < a.sophantu(); i++) 82 | { 83 | if (a[i].name_contact() == x) 84 | { 85 | temp = true; 86 | a.xoa(i); 87 | } 88 | } 89 | if (temp) 90 | cout << "Xoa thanh cong!\n\n"; 91 | else 92 | cout << "Khong co lien he trung khop\n\n"; 93 | } 94 | break; 95 | case 2: 96 | { 97 | cout << "Nhap so dien thoai lien he can xoa: "; 98 | string x; 99 | cin >> x; 100 | bool temp = false; 101 | for (int i = 0; i < a.sophantu(); i++) 102 | { 103 | if (a[i].number_phone() == x) 104 | { 105 | temp = true; 106 | a.xoa(i); 107 | } 108 | } 109 | if (temp) 110 | cout << "Xoa thanh cong!\n\n"; 111 | else 112 | cout << "Khong co lien he trung khop\n\n"; 113 | break; 114 | } 115 | case 3: 116 | { 117 | cout << "Nhap email lien he can xoa: "; 118 | string x; 119 | cin >> x; 120 | bool temp = false; 121 | for (int i = 0; i < a.sophantu(); i++) 122 | { 123 | if (a[i].email_contact() == x) 124 | { 125 | temp = true; 126 | a.xoa(i); 127 | } 128 | } 129 | if (temp) 130 | cout << "Xoa thanh cong!\n\n"; 131 | else 132 | cout << "Khong co lien he trung khop\n\n"; 133 | break; 134 | } 135 | default: 136 | cout << "Thao tac khong hop le!\n"; 137 | break; 138 | } 139 | cout << "----------------------------------\n"; 140 | cout << "\nNhap phim bat ky de quay lai: "; 141 | char y; 142 | cin >> y; 143 | } 144 | void search() 145 | { 146 | cout << "----------------------------------\n"; 147 | cout << "Ban muon tim theo:\n"; 148 | cout << "\t1. Ho ten.\n"; 149 | cout << "\t2. So dien thoai.\n"; 150 | cout << "\t3. Email.\n"; 151 | int cnt; 152 | cin >> cnt; 153 | switch (cnt) 154 | { 155 | case 1: 156 | { 157 | cout << "Nhap ho ten can tim: "; 158 | string x; 159 | cin.ignore(1); 160 | getline(cin, x); 161 | bool temp = false; 162 | for (int i = 0; i < a.sophantu(); i++) 163 | { 164 | if (x == a[i].name_contact()) 165 | { 166 | if (!temp) 167 | { 168 | cout << "\nDanh sach cac lien he tim thay: \n"; 169 | temp = true; 170 | } 171 | cout << a[i] << endl; 172 | } 173 | } 174 | if (!temp) 175 | cout << "Khong tim thay lien he!\n"; 176 | break; 177 | } 178 | case 2: 179 | { 180 | cout << "Nhap so dien thoai can tim: "; 181 | string x; 182 | cin >> x; 183 | bool temp = false; 184 | for (int i = 0; i < a.sophantu(); i++) 185 | { 186 | if (x == a[i].number_phone()) 187 | { 188 | if (!temp) 189 | { 190 | cout << "\nDanh sach cac lien he tim thay: \n"; 191 | temp = true; 192 | } 193 | cout << a[i] << endl; 194 | } 195 | } 196 | if (!temp) 197 | cout << "Khong tim thay lien he!\n"; 198 | break; 199 | cout << "\nNhap phim bat ky de quay lai: "; 200 | char y; 201 | cin >> y; 202 | } 203 | case 3: 204 | { 205 | cout << "Nhap email can tim: "; 206 | string x; 207 | cin >> x; 208 | bool temp = false; 209 | for (int i = 0; i < a.sophantu(); i++) 210 | { 211 | if (x == a[i].email_contact()) 212 | { 213 | if (!temp) 214 | { 215 | cout << "\nDanh sach cac lien he tim thay: \n"; 216 | temp = true; 217 | } 218 | cout << a[i] << endl; 219 | } 220 | } 221 | if (!temp) 222 | cout << "Khong tim thay lien he!\n"; 223 | break; 224 | } 225 | default: 226 | cout << "Thao tac khong hop le!\n"; 227 | break; 228 | cout << "----------------------------------\n"; 229 | } 230 | cout << "\nNhap phim bat ky de quay lai: "; 231 | char y; 232 | cin >> y; 233 | } 234 | void sort() 235 | { 236 | for (int i = 0; i < a.sophantu(); i++) 237 | { 238 | for (int j = i; j < a.sophantu(); j++) 239 | { 240 | if (a[i].name_contact() > a[j].name_contact()) 241 | { 242 | contact x = a[i]; 243 | a[i] = a[j]; 244 | a[j] = x; 245 | } 246 | } 247 | } 248 | } 249 | void list_contact() 250 | { 251 | sort(); 252 | cout << "Danh sach cac lien he:\n"; 253 | for (int i = 0; i < a.sophantu(); i++) 254 | { 255 | cout << a[i] << endl; 256 | } 257 | } 258 | int size() { return a.sophantu(); } 259 | }; 260 | #endif -------------------------------------------------------------------------------- /BTL_2023/linkedlist/cbApp.cpp: -------------------------------------------------------------------------------- 1 | #include "danh_sach_can_bo.cpp" 2 | #ifndef HEADER_NAME 3 | #define HEADER_NAME 4 | using namespace std; 5 | 6 | class app 7 | { 8 | list_cb a; 9 | bool cnt = true; 10 | 11 | protected: 12 | bool confirm(); 13 | void create_new(); 14 | void add(); 15 | void show(); 16 | void listStatistics(); 17 | void search(int index); 18 | void sort(); 19 | void home(); 20 | void end_task(); 21 | 22 | public: 23 | void run(); 24 | }; 25 | bool app::confirm() 26 | { 27 | int tmp = 0; 28 | while (tmp < 3) 29 | { 30 | cout << "Nhap y de quay lai hoac n de thoat: "; 31 | char t; 32 | cin >> t; 33 | if (t == 'y') 34 | return true; 35 | else if (t == 'n') 36 | return false; 37 | else 38 | { 39 | system("cls"); 40 | cout << "\n--------------------------^-^------------------------------"; 41 | cout << "\nThao tac khong hop le.\n"; 42 | tmp++; 43 | } 44 | } 45 | cout << "Ban da nhap sai qua nhieu lan. Thoat chuong trinh.\n"; 46 | cin.get(); 47 | return false; 48 | } 49 | void app::create_new() 50 | { 51 | if (cnt) 52 | { 53 | system("cls"); 54 | cout << "\n--------------------------^-^------------------------------\n"; 55 | cnt = a.create_list(); 56 | cout << "--------------------------^-^------------------------------\n"; 57 | if (confirm()) 58 | home(); 59 | else 60 | return; 61 | } 62 | else 63 | { 64 | system("cls"); 65 | cout << "\n--------------------------^-^------------------------------\n"; 66 | cout << "Luu y! Viec tao moi se xoa di danh sach dang co.\n"; 67 | cout << "Nhap 'y' de xac nhan hoac 'n' de quay lai: "; 68 | cout << endl; 69 | char x; 70 | int tmp = 0; 71 | while (tmp < 3) 72 | { 73 | cin >> x; 74 | tmp++; 75 | if (x == 'y' || x == 'n') 76 | break; 77 | if (tmp == 3) 78 | { 79 | cout << "Nhap qua nhieu lan. Thoat chuong trinh.\n"; 80 | return; 81 | } 82 | cout << "Thao tac khong hop le. Nhap lai: "; 83 | } 84 | 85 | if (x == 'y') 86 | { 87 | system("cls"); 88 | a.del(); 89 | a = Don_list(); 90 | cnt = a.create_list(); 91 | cout << "--------------------------^-^------------------------------\n"; 92 | if (confirm()) 93 | home(); 94 | else 95 | return; 96 | } 97 | else 98 | home(); 99 | } 100 | } 101 | void app::add() 102 | { 103 | system("cls"); 104 | cout << "\n--------------------------^-^------------------------------\n"; 105 | a.add(); 106 | cout << "\n--------------------------^-^------------------------------\n"; 107 | if (confirm()) 108 | home(); 109 | else 110 | return; 111 | } 112 | void app::show() 113 | { 114 | system("cls"); 115 | cout << "\n--------------------------^-^------------------------------\n"; 116 | a.display(); 117 | cout << "\n--------------------------^-^------------------------------\n"; 118 | if (confirm()) 119 | home(); 120 | else 121 | return; 122 | } 123 | void app::listStatistics() 124 | { 125 | system("cls"); 126 | cout << "\n--------------------------^-^------------------------------\n"; 127 | a.filterList(); 128 | cout << "\n--------------------------^-^------------------------------\n"; 129 | if (confirm()) 130 | home(); 131 | else 132 | return; 133 | } 134 | void app::search(int index) 135 | { 136 | if (index) 137 | { 138 | system("cls"); 139 | cout << "\n--------------------------^-^------------------------------\n"; 140 | cout << "Nhap chuc vu can tim: "; 141 | string y; 142 | cin.ignore(1); 143 | getline(cin, y); 144 | a.search(y); 145 | cout << "\n\t--------------------------^-^------------------------------\n"; 146 | if (confirm()) 147 | home(); 148 | else 149 | return; 150 | } 151 | else 152 | { 153 | system("cls"); 154 | cout << "\n--------------------------^-^------------------------------\n"; 155 | cout << "Nhap he so luong: "; 156 | string z; 157 | float y; 158 | cin >> y; 159 | cout << "Phong ban can can tim: "; 160 | cin.ignore(1); 161 | getline(cin, z); 162 | a.search(y, z); 163 | cout << "\n--------------------------^-^------------------------------\n"; 164 | if (confirm()) 165 | home(); 166 | else 167 | return; 168 | } 169 | } 170 | void app::sort() 171 | { 172 | system("cls"); 173 | cout << "\n--------------------------^-^------------------------------\n"; 174 | cout << "Sap xep thanh cong!\nDanh sach sau khi sap xep:\n\n"; 175 | a.sort(); 176 | a.display(); 177 | if (confirm()) 178 | home(); 179 | else 180 | return; 181 | } 182 | void app::home() 183 | { 184 | system("cls"); 185 | if (cnt) 186 | { 187 | cout << "\t-----------------^-^-----------------\n"; 188 | cout << "\t|\tDanh sach can bo trong |\n"; 189 | cout << "\t-------------------------------------\n"; 190 | cout << "\t|\t1. Tao moi danh sach |\n"; 191 | cout << "\t|\t2. Thoat chuong trinh. |\n"; 192 | cout << "\t-------------------------------------\n"; 193 | int n; 194 | cout << "Chon tac vu mong muon: "; 195 | cin >> n; 196 | switch (n) 197 | { 198 | case 1: 199 | { 200 | create_new(); 201 | break; 202 | } 203 | case 2: 204 | return; 205 | default: 206 | { 207 | cout << "Thao tac khong hop le!\n"; 208 | if (confirm()) 209 | home(); 210 | else 211 | return; 212 | break; 213 | } 214 | } 215 | } 216 | else 217 | { 218 | cout << "\t--------------------------^-^------------------------------\n"; 219 | cout << "\t|\t1. Tao danh sach moi. |\n"; 220 | cout << "\t|\t2. Them mot can bo moi. |\n"; 221 | cout << "\t|\t3. Xem danh sach can bo. |\n"; 222 | cout << "\t|\t4. Thong ke can bo co he so luong tren 4.4. |\n"; 223 | cout << "\t|\t5. Loc theo chuc vu. |\n"; 224 | cout << "\t|\t6. Loc theo he so luong va phong ban. |\n"; 225 | cout << "\t|\t7. Sap xep danh sach. |\n"; 226 | cout << "\t|\t8. Thoat chuong trinh. |\n"; 227 | cout << "\t-----------------------------------------------------------\n"; 228 | int n; 229 | cout << "Chon tac vu mong muon: "; 230 | cin >> n; 231 | switch (n) 232 | { 233 | case 1: 234 | { 235 | create_new(); 236 | break; 237 | } 238 | case 2: 239 | { 240 | add(); 241 | break; 242 | } 243 | case 3: 244 | { 245 | show(); 246 | break; 247 | } 248 | case 4: 249 | { 250 | listStatistics(); 251 | break; 252 | } 253 | case 5: 254 | { 255 | search(1); 256 | break; 257 | } 258 | case 6: 259 | { 260 | search(0); 261 | break; 262 | } 263 | case 7: 264 | { 265 | sort(); 266 | break; 267 | } 268 | case 8: 269 | return; 270 | default: 271 | { 272 | cout << "Thao tac khong hop le!\n"; 273 | if (confirm()) 274 | home(); 275 | else 276 | return; 277 | break; 278 | } 279 | } 280 | } 281 | } 282 | void app::end_task() 283 | { 284 | system("cls"); 285 | cout << "\t\t __ __" << endl; 286 | cout << "\t\t ******** ********" << endl; 287 | cout << "\t\t****____________****" << endl; 288 | cout << "\t\t****| Goodbye! |***" << endl; 289 | cout << "\t\t ***------------**" << endl; 290 | cout << "\t\t *************" << endl; 291 | cout << "\t\t *******" << endl; 292 | cout << "\t\t *" << endl; 293 | } 294 | void app::run() 295 | { 296 | home(); 297 | end_task(); 298 | } 299 | #endif -------------------------------------------------------------------------------- /BTL_2023/linkedlist/danh_sach_can_bo.cpp: -------------------------------------------------------------------------------- 1 | #include "can_bo.cpp" 2 | #include "linked_list.cpp" 3 | #ifndef _danh_sach_cpp 4 | #define _danh_sach_cpp 5 | using namespace std; 6 | 7 | class list_cb 8 | { 9 | Don_list a; 10 | 11 | public: 12 | list_cb() {} 13 | list_cb(Don_list a) 14 | { 15 | this->a = a; 16 | } 17 | bool filter(can_bo x); 18 | bool create_list(); 19 | void add(); 20 | void del() 21 | { 22 | a.~Don_list(); 23 | } 24 | void sort(); 25 | void filterList(); 26 | void display(); 27 | void search(string cvu); 28 | void search(float hsl, string phong); 29 | }; 30 | bool list_cb::filter(can_bo x) 31 | { 32 | for (iter i = a.dau(); i != nullptr; i++) 33 | { 34 | if ((*i) == x) 35 | { 36 | cout << "Can bo vua nhap da co trong danh sach!\n"; 37 | return false; 38 | } 39 | if ((*i).ma_can_bo() == x.ma_can_bo()) 40 | { 41 | cout << "Ma can bo da ton tai!\n"; 42 | return false; 43 | } 44 | } 45 | return true; 46 | } 47 | bool list_cb::create_list() 48 | { 49 | int i = 0, _t = 0; 50 | bool x; 51 | while (1) 52 | { 53 | system("cls"); 54 | cout << "\nTao danh sach can bo\nLuu y nhap ma can bo nho hon 1 de dung!\n\n"; 55 | cout << "Nhap thong tin can bo thu " << ++i << endl; 56 | can_bo temp; 57 | x = temp.input(); 58 | if (!filter(temp)) 59 | { 60 | cout << "Ban co muon nhap lai?\n"; 61 | cout << "Nhap 'y' de nhap lai hoac 'n' de dung: "; 62 | char t; 63 | cin >> t; 64 | while (t != 'y' && t != 'n') 65 | { 66 | if (_t == 2) 67 | break; 68 | _t++; 69 | system("cls"); 70 | cout << "Khong hop le, vui long nhap lai.\n"; 71 | cout << "Nhap 'y' de nhap lai hoac 'n' de dung: "; 72 | cin >> t; 73 | } 74 | if (t == 'y') 75 | { 76 | i--; 77 | continue; 78 | } 79 | else 80 | x = false; 81 | } 82 | if (!x) 83 | break; 84 | a.push_back(temp); 85 | } 86 | system("cls"); 87 | if (i == 1 && !x) 88 | { 89 | if (_t == 2) 90 | cout << "Ban da nhap sai qua nhieu lan!\nThoat tac vu nhap.\n"; 91 | else 92 | cout << "Huy lenh nhap!\n"; 93 | 94 | return true; 95 | } 96 | else 97 | { 98 | if (_t == 2) 99 | cout << "Ban da nhap sai qua nhieu lan!\nThoat tac vu nhap.\n"; 100 | else 101 | cout << "\nTao moi hoan tat!\n"; 102 | return false; 103 | } 104 | } 105 | void list_cb::add() 106 | { 107 | cout << "Hien tai danh sach co " << a.size() << " can bo.\n"; 108 | cout << "Ban muon chon vi tri se them?\n"; 109 | cout << "\t1. Chon vi tri.\n"; 110 | cout << "\t2. Khong chon\n"; 111 | char t; 112 | cout << "Tac vu: "; 113 | cin >> t; 114 | can_bo temp; 115 | switch (t) 116 | { 117 | case '1': 118 | { 119 | cout << "\tChon vi tri muon them: "; 120 | int n, _t = 0; 121 | cin >> n; 122 | while (n < 1 || n > a.size() + 1) 123 | { 124 | system("cls"); 125 | if (_t == 2) 126 | { 127 | cout << "Nhap sai qua nhieu lan, thoat tac vu.\n"; 128 | return; 129 | } 130 | _t++; 131 | cout << "Khong hop le, vui long nhap lai: "; 132 | cin >> n; 133 | } 134 | system("cls"); 135 | cout << "Nhap thong tin can bo can them\n"; 136 | cin >> temp; 137 | system("cls"); 138 | while (!filter(temp)) 139 | { 140 | _t = 0; 141 | cout << "Ban co muon nhap lai?\n"; 142 | cout << "Nhap 'y' de nhap lai hoac 'n' de dung: "; 143 | char x; 144 | cin >> x; 145 | 146 | while (x != 'y' && x != 'n') 147 | { 148 | if (_t == 2) 149 | { 150 | cout << "Nhap sai qua nhieu lan. Thoat tac vu!\n"; 151 | return; 152 | } 153 | _t++; 154 | system("cls"); 155 | cout << "Khong hop le, vui long nhap lai.\n"; 156 | cout << "Nhap 'y' de nhap lai hoac 'n' de dung: "; 157 | cin >> x; 158 | } 159 | system("cls"); 160 | if (x == 'y') 161 | { 162 | cout << "Nhap thong tin can bo can them\n"; 163 | cin >> temp; 164 | system("cls"); 165 | continue; 166 | } 167 | else 168 | return; 169 | } 170 | if (n == 1) 171 | a.push_front(temp); 172 | else if (n == a.size() + 1) 173 | a.push_back(temp); 174 | else 175 | { 176 | int j = 1; 177 | for (iter i = a.dau(); i != nullptr; i++, j++) 178 | if (j == n - 1) 179 | { 180 | a.insert(i.getnode(), temp); 181 | break; 182 | } 183 | } 184 | break; 185 | } 186 | case '2': 187 | { 188 | system("cls"); 189 | cout << "Nhap thong tin can bo can them\n"; 190 | cin >> temp; 191 | system("cls"); 192 | int _t = 0; 193 | while (!filter(temp)) 194 | { 195 | _t = 0; 196 | cout << "Ban co muon nhap lai?\n"; 197 | cout << "Nhap 'y' de nhap lai hoac 'n' de dung: "; 198 | char x; 199 | cin >> x; 200 | 201 | while (x != 'y' && x != 'n') 202 | { 203 | if (_t == 2) 204 | break; 205 | _t++; 206 | system("cls"); 207 | cout << "Khong hop le, vui long nhap lai.\n"; 208 | cout << "Nhap 'y' de nhap lai hoac 'n' de dung: "; 209 | cin >> x; 210 | } 211 | system("cls"); 212 | if (x == 'y') 213 | { 214 | cout << "Nhap thong tin can bo can them\n"; 215 | cin >> temp; 216 | system("cls"); 217 | continue; 218 | } 219 | else 220 | return; 221 | } 222 | a.push_back(temp); 223 | break; 224 | } 225 | default: 226 | cout << "\tThao tac khong hop le!\n"; 227 | break; 228 | } 229 | cout << "Da them thanh cong can bo \"" << temp.ho_ten() << "\" vao danh sach.\n"; 230 | } 231 | void list_cb::sort() 232 | { 233 | for (iter i = a.dau(); i != nullptr; i++) 234 | { 235 | for (iter j = i; j != nullptr; j++) 236 | { 237 | can_bo X = *i; 238 | can_bo Y = *j; 239 | if (_cmp(X.Ten(), Y.Ten()) > 0 || (!_cmp(X.Ten(), Y.Ten()) && _cmp(X.Ho(), Y.Ho()) > 0)) 240 | { 241 | j.getnode()->setE(X); 242 | i.getnode()->setE(Y); 243 | } 244 | } 245 | } 246 | } 247 | void list_cb::filterList() 248 | { 249 | int j = 0; 250 | for (iter i = a.dau(); i != nullptr; i++) 251 | { 252 | if ((*i).he_so_luong() >= 4.4) 253 | { 254 | if (!j) 255 | cout << "Danh sach cac can bo co he so luong tren 4.4 la:\n\n"; 256 | cout << ++j << ". " << *i << endl; 257 | } 258 | } 259 | if (!j) 260 | cout << "Khong co can bo co he so luong tren 4.4\n"; 261 | return; 262 | } 263 | void list_cb::display() 264 | { 265 | int j = 0; 266 | for (iter i = a.dau(); i != nullptr; i++) 267 | { 268 | cout << ++j << ". " << *i << endl; 269 | } 270 | return; 271 | } 272 | void list_cb::search(string cvu) 273 | { 274 | int j = 0; 275 | for (iter i = a.dau(); i != nullptr; i++) 276 | { 277 | if (!_cmp((*i).chuc_vu(), cvu)) 278 | { 279 | if (!j) 280 | cout << "Danh sach cac can bo co chuc vu \"" << cvu << "\" la:\n\n"; 281 | cout << ++j << ". " << *i << endl; 282 | } 283 | } 284 | if (!j) 285 | cout << "Khong co can bo giu chuc vu \"" << cvu << "\".\n"; 286 | return; 287 | } 288 | void list_cb::search(float hsl, string phong) 289 | { 290 | int j = 0; 291 | for (iter i = a.dau(); i != nullptr; i++) 292 | { 293 | if ((*i).he_so_luong() >= hsl && !_cmp((*i).phong_ban(), phong)) 294 | { 295 | if (!j) 296 | cout << "Danh sach cac can bo co he so luong tren " << hsl << " o phong \"" << phong << "\" la:\n\n"; 297 | cout << ++j << ". " << *i << endl; 298 | } 299 | } 300 | if (!j) 301 | cout << "Khong co can bo co he so luong " << hsl << " o phong " << phong << endl; 302 | return; 303 | } 304 | #endif -------------------------------------------------------------------------------- /BTL_2023/graph/danhsachke.cpp: -------------------------------------------------------------------------------- 1 | #include "linked_list.cpp" 2 | #ifndef _adjacency_list 3 | #define _adjacency_list 4 | using namespace std; 5 | 6 | class Graph 7 | { 8 | int n, m, _n; 9 | Don_list> *a; 10 | 11 | protected: 12 | bool confirm(); 13 | 14 | public: 15 | Graph() 16 | { 17 | this->m = 0; 18 | this->n = 0; 19 | this->a = nullptr; 20 | } 21 | Graph(int n, int _n, int m); 22 | Graph &operator=(const Graph &x); 23 | ~Graph() 24 | { 25 | delete[] a; 26 | } 27 | void add(int s, int d, int tso); 28 | friend ifstream &operator>>(ifstream &cin, Graph &x) 29 | { 30 | cin >> x._n >> x.m; 31 | int tmp[x.m][2], tso[x.m]; 32 | for (int i = 0; i < x.m; i++) 33 | { 34 | cin >> tmp[i][0] >> tmp[i][1] >> tso[i]; 35 | x.n = max(tmp[i][0], max(tmp[i][1], x.n)); 36 | } 37 | 38 | x.n++; 39 | int j = 0; 40 | x.a = new Don_list>[x.n]; 41 | for (int i = 0; i < x.n; i++) 42 | { 43 | x.a[i].push_back({i, 0}); 44 | } 45 | for (int i = 0; i < x.m; i++) 46 | { 47 | x.add(tmp[i][0], tmp[i][1], tso[i]); 48 | } 49 | cout << "Doc thanh cong!\n"; 50 | return cin; 51 | } 52 | friend ofstream &operator<<(ofstream &cout, const Graph &x) 53 | { 54 | int tmp[x.n * x.n] = {0}; 55 | cout << "Số đỉnh: " << x._n << endl; 56 | for (int i = 0; i < x.n; i++) 57 | { 58 | iter> temp = x.a[i].dau(); 59 | temp++; 60 | if (temp != nullptr) 61 | { 62 | cout << "Đỉnh " << x.a[i].front().first << " kết nối với:\n"; 63 | int j = x.a[i].front().first; 64 | while (temp != nullptr) 65 | { 66 | int k = (*temp).first; 67 | if (!tmp[j * x.n + k]) 68 | { 69 | tmp[j * x.n + k] = 1; 70 | cout << "\tĐỉnh " << k << " có trọng số " << (*temp).second << endl; 71 | } 72 | temp++; 73 | } 74 | cout << endl; 75 | } 76 | } 77 | return cout; 78 | } 79 | void _dfs(int u, int t[]); 80 | void DFS(int u, int t[]); 81 | void _bfs(int u, int t[], int _t[], int &j, ofstream &output); 82 | void BFS(); 83 | void _DFS(); 84 | int _dem_lien_thong(); 85 | void con(ofstream &output); 86 | void dijkstra(); 87 | void input_Gr(ofstream &output); 88 | }; 89 | Graph::Graph(int n, int _n, int m) 90 | { 91 | this->_n = _n; 92 | this->m = m; 93 | this->n = n; 94 | this->a = new Don_list>[n]; 95 | int j = 0; 96 | for (int i = 0; i < n; i++) 97 | { 98 | a[i].push_back({i, 0}); 99 | } 100 | } 101 | Graph &Graph::operator=(const Graph &x) 102 | { 103 | delete[] this->a; 104 | this->_n = x._n; 105 | this->m = x.m; 106 | this->n = x.n; 107 | this->a = new Don_list>[x.n]; 108 | for (int i = 0; i < x.n; i++) 109 | { 110 | iter> temp = x.a[i].dau(); 111 | while (temp != nullptr) 112 | { 113 | this->a[i].push_back(*temp); 114 | temp++; 115 | } 116 | } 117 | return *this; 118 | } 119 | void Graph::add(int s, int d, int tso) 120 | { 121 | a[s].push_back({d, tso}); 122 | a[d].push_back({s, tso}); 123 | } 124 | void Graph::_dfs(int u, int t[]) 125 | { 126 | t[u] = 1; 127 | iter> temp = a[u].dau(); 128 | while (temp != nullptr) 129 | { 130 | int v = (*temp).first; 131 | if (!t[v]) 132 | _dfs(v, t); 133 | temp++; 134 | } 135 | } 136 | void Graph::DFS(int u, int t[]) 137 | { 138 | cout << u << " "; 139 | t[u] = 1; 140 | iter> temp = a[u].dau(); 141 | while (temp != nullptr) 142 | { 143 | int v = (*temp).first; 144 | if (!t[v]) 145 | DFS(v, t); 146 | temp++; 147 | } 148 | } 149 | void Graph::_bfs(int u, int t[], int _t[], int &j, ofstream &output) 150 | { 151 | bool cnt = true; 152 | queue c; 153 | c.push(u); 154 | while (!c.empty()) 155 | { 156 | int k = c.front(); 157 | c.pop(); 158 | t[k] = 1; 159 | iter> temp = a[k].dau(); 160 | while (temp != nullptr) 161 | { 162 | int v = (*temp).first; 163 | int w = (*temp).second; 164 | if (!t[v] && !_t[k * n + v]) 165 | { 166 | if (cnt) 167 | { 168 | output << "Đồ thị con thứ " << j << ":\n"; 169 | cout << "Do thi con thu " << j++ << ":\n"; 170 | cnt = false; 171 | } 172 | cout << "\t" << k << " " << v << " " << w << endl; 173 | output << "\t" << k << " " << v << " " << w << endl; 174 | c.push(v); 175 | _t[k * n + v] = 1; 176 | } 177 | temp++; 178 | } 179 | } 180 | } 181 | void Graph::BFS() 182 | { 183 | int t[n + 1] = {0}; 184 | queue c; 185 | c.push(1); 186 | while (!c.empty()) 187 | { 188 | int k = c.front(); 189 | c.pop(); 190 | if (!t[k]) 191 | cout << k << " "; 192 | t[k] = 1; 193 | iter> temp = a[k].dau(); 194 | while (temp != nullptr) 195 | { 196 | int v = (*temp).first; 197 | if (!t[v]) 198 | c.push(v); 199 | temp++; 200 | } 201 | } 202 | } 203 | void Graph::_DFS() 204 | { 205 | if (_dem_lien_thong() == 1) 206 | { 207 | int t[n + 1] = {0}; 208 | DFS(1, t); 209 | cout << "\nTac vu thanh cong!\n"; 210 | } 211 | else 212 | cout << "Do thi khong lien thong.\nHuy lenh DFS!\n"; 213 | } 214 | int Graph::_dem_lien_thong() 215 | { 216 | int t[n + 1] = {0}, res = 0; 217 | for (int i = 1; i < n; i++) 218 | { 219 | iter> temp = a[i].dau().getnode()->getNext(); 220 | if (!t[i] && temp != nullptr) 221 | { 222 | res++; 223 | _dfs(i, t); 224 | cout << endl; 225 | } 226 | } 227 | return res; 228 | } 229 | void Graph::con(ofstream &output) 230 | { 231 | output << "Danh sách đồ thị con:\n"; 232 | cout << "\nDanh sach do thi con\n"; 233 | int _t[n * n + 1] = {0}, t[n + 1] = {0}, j = 1; 234 | for (int i = 0; i < n; i++) 235 | if (!t[i]) 236 | _bfs(i, t, _t, j, output); 237 | } 238 | void Graph::dijkstra() 239 | { 240 | cout << "Nhap dinh dau: "; 241 | int dau, cuoi; 242 | cin >> dau; 243 | cout << "Nhap dinh cuoi: "; 244 | cin >> cuoi; 245 | if (a[dau].dau() != nullptr && a[cuoi].dau() != nullptr) 246 | { 247 | vector d(n, INT_MAX), res(n); 248 | d[dau] = 0; 249 | priority_queue, vector>, greater>> q; 250 | q.push({0, dau}); 251 | while (!q.empty()) 252 | { 253 | pair top = q.top(); 254 | q.pop(); 255 | int u = top.second; 256 | float kc = top.first; 257 | iter> temp = a[u].dau(); 258 | while (temp != nullptr) 259 | { 260 | int v = (*temp).first; 261 | float w = (*temp).second; 262 | if (d[v] > d[u] + w) 263 | { 264 | res[v] = u; 265 | d[v] = d[u] + w; 266 | q.push({d[v], v}); 267 | } 268 | temp++; 269 | } 270 | } 271 | cout << "Duong di ngan nhat tu dinh " << dau << " den dinh " << cuoi << " la: "; 272 | vector _res; 273 | _res.push_back(cuoi); 274 | int k = res[cuoi]; 275 | while (k != dau) 276 | { 277 | _res.push_back(k); 278 | k = res[k]; 279 | } 280 | _res.push_back(dau); 281 | for (int i = _res.size() - 1; i >= 0; i--) 282 | cout << _res[i] << " "; 283 | cout << "\nKhoang cach giua hai dinh la: " << d[cuoi] << endl; 284 | } 285 | else 286 | cout << "Dinh dau hoac cuoi khong hop le!\n"; 287 | } 288 | void Graph::input_Gr(ofstream &output) 289 | { 290 | cout << "Nhap so dinh: "; 291 | int n; 292 | cin >> n; 293 | output << n << " "; 294 | cout << "Nhap so canh: "; 295 | cin >> n; 296 | output << n << "\n"; 297 | for (int i = 0; i < n; i++) 298 | { 299 | int x, y, w; 300 | cout << "Nhap canh thu " << i + 1 << " va trong so: "; 301 | cin >> x >> y >> w; 302 | output << x << " " << y << " " << w << endl; 303 | } 304 | } 305 | bool Graph::confirm() 306 | { 307 | int tmp = 0; 308 | while (tmp < 3) 309 | { 310 | cout << "Nhap y de quay lai hoac n de thoat: "; 311 | char t; 312 | cin >> t; 313 | if (t == 'y') 314 | return true; 315 | else if (t == 'n') 316 | return false; 317 | else 318 | { 319 | cout << "\nThao tac khong hop le.\n"; 320 | tmp++; 321 | } 322 | } 323 | cout << "Ban da nhap sai qua nhieu lan. Thoat chuong trinh.\n"; 324 | return false; 325 | } 326 | #endif -------------------------------------------------------------------------------- /BTL_2023/graph/graphApp.cpp: -------------------------------------------------------------------------------- 1 | #include "danhsachke.cpp" 2 | #ifndef _app_do_thi_ 3 | #define _app_do_thi_ 4 | using namespace std; 5 | 6 | class app 7 | { 8 | Graph a; 9 | bool cnt; 10 | string input, output, child; 11 | 12 | protected: 13 | bool confirm(); 14 | void home(); 15 | void end_task(); 16 | 17 | public: 18 | app() 19 | { 20 | cnt = true; 21 | input = "input.txt"; 22 | output = "output.txt"; 23 | child = "child.txt"; 24 | } 25 | void inputFile(); 26 | void inputKeyBoard(); 27 | void Input(); 28 | void Output(); 29 | void generateSubgraphs(); 30 | void bfs(); 31 | void dfs(); 32 | void dijkstra(); 33 | void run(); 34 | }; 35 | bool app::confirm() 36 | { 37 | int tmp = 0; 38 | while (tmp < 3) 39 | { 40 | cout << "Nhap y de quay lai hoac n de thoat: "; 41 | char t; 42 | cin >> t; 43 | if (t == 'y') 44 | return true; 45 | else if (t == 'n') 46 | return false; 47 | else 48 | { 49 | system("cls"); 50 | cout << "\nThao tac khong hop le.\n"; 51 | tmp++; 52 | } 53 | } 54 | cout << "Ban da nhap sai qua nhieu lan. Thoat chuong trinh.\n\n"; 55 | cin.get(); 56 | return false; 57 | } 58 | void app::inputFile() 59 | { 60 | system("cls"); 61 | cout << "\n--------^-^--------\n"; 62 | cout << "1. Nhap tu file goc \"input.txt\".\n"; 63 | cout << "2. Nhap tu file khac.\n"; 64 | int _n; 65 | cout << "Nhap lua chon: "; 66 | cin >> _n; 67 | system("cls"); 68 | if (_n == 2) 69 | { 70 | cout << "Nhap ten file: "; 71 | string _temp; 72 | cin >> _temp; 73 | input = _temp; 74 | system("cls"); 75 | } 76 | ifstream inp(input); 77 | if (!inp.is_open()) 78 | { 79 | cout << "Khong the mo file.\n"; 80 | cout << "--------------------\n"; 81 | input = "input.txt"; 82 | if (confirm()) 83 | home(); 84 | else 85 | return; 86 | } 87 | inp >> a; 88 | inp.close(); 89 | cnt = false; 90 | cout << "--------------------\n"; 91 | cout << endl; 92 | if (confirm()) 93 | home(); 94 | else 95 | return; 96 | } 97 | void app::inputKeyBoard() 98 | { 99 | system("cls"); 100 | cout << "\n--------^-^--------\n"; 101 | ofstream out(input); 102 | a.input_Gr(out); 103 | out.close(); 104 | ifstream inp(input); 105 | inp >> a; 106 | inp.close(); 107 | cnt = false; 108 | cout << "\n-----------------------------------\n"; 109 | cout << endl; 110 | if (confirm()) 111 | home(); 112 | else 113 | return; 114 | } 115 | void app::Input() 116 | { 117 | system("cls"); 118 | cout << "\n--------------------------^-^------------------------------\n"; 119 | char t; 120 | cout << "Nhap vao do thi moi se xoa di do thi cu.\n"; 121 | cout << "Nhap 'y' de tiep tuc hoac 'n' de quay lai: "; 122 | int tmp = 0; 123 | while (tmp < 3) 124 | { 125 | cin >> t; 126 | tmp++; 127 | if (t == 'y' || t == 'n') 128 | break; 129 | if (tmp == 3) 130 | { 131 | cout << "Nhap qua nhieu lan. Thoat chuong trinh.\n"; 132 | return; 133 | } 134 | cout << "Thao tac khong hop le. Nhap lai: "; 135 | } 136 | if (t == 'n') 137 | home(); 138 | system("cls"); 139 | cout << "\n--------^-^--------\n"; 140 | cout << "1. Nhap tu file goc \"input.txt\".\n"; 141 | cout << "2. Nhap tu file khac.\n"; 142 | cout << "3. Nhap tu ban phim.\n"; 143 | int _n; 144 | cout << "\nNhap lua chon: "; 145 | cin >> _n; 146 | system("cls"); 147 | switch (_n) 148 | { 149 | case 1: 150 | { 151 | input = "input.txt"; 152 | ifstream inp(input); 153 | inp >> a; 154 | inp.close(); 155 | break; 156 | } 157 | case 2: 158 | { 159 | cout << "Nhap ten file: "; 160 | string _temp; 161 | cin >> _temp; 162 | input = _temp; 163 | system("cls"); 164 | ifstream inp(input); 165 | if (!inp.is_open()) 166 | { 167 | cout << "Khong the mo file.\n"; 168 | cout << "--------------------\n"; 169 | input = "input.txt"; 170 | if (confirm()) 171 | home(); 172 | else 173 | return; 174 | } 175 | else 176 | { 177 | ifstream inp(input); 178 | inp >> a; 179 | inp.close(); 180 | } 181 | break; 182 | } 183 | case 3: 184 | { 185 | cout << "Ban dang thao tac tren file \"" << input << "\", ban co doi file?\n"; 186 | cout << "Nhap \"y\" de doi hoac \"n\" de tiep tuc: "; 187 | char _t; 188 | cin >> _t; 189 | system("cls"); 190 | if (_t == 'y') 191 | { 192 | cout << "Nhap ten file: "; 193 | string _temp; 194 | cin >> _temp; 195 | input = _temp; 196 | system("cls"); 197 | ifstream inp(input); 198 | if (!inp.is_open()) 199 | { 200 | cout << "Khong the mo file.\n"; 201 | cout << "--------------------\n"; 202 | input = "input.txt"; 203 | if (confirm()) 204 | home(); 205 | else 206 | return; 207 | } 208 | } 209 | ofstream out(input); 210 | a.input_Gr(out); 211 | out.close(); 212 | ifstream inp(input); 213 | inp >> a; 214 | inp.close(); 215 | cnt = false; 216 | break; 217 | } 218 | } 219 | cout << "\n--------------------------^-^------------------------------\n"; 220 | cout << endl; 221 | if (confirm()) 222 | home(); 223 | else 224 | return; 225 | } 226 | void app::Output() 227 | { 228 | system("cls"); 229 | cout << "\n --------^-^--------\n"; 230 | ofstream out(output); 231 | out << a; 232 | out.close(); 233 | cout << "Tac vu thanh cong!\n"; 234 | cout << "\n --------^-^--------\n"; 235 | cout << endl; 236 | if (confirm()) 237 | home(); 238 | else 239 | return; 240 | } 241 | void app::generateSubgraphs() 242 | { 243 | system("cls"); 244 | cout << "\n--------------------------^-^------------------------------\n"; 245 | ofstream ch(child); 246 | a.con(ch); 247 | cout << "Tac vu thanh cong!\n"; 248 | cout << "\n--------------------------^-^------------------------------\n"; 249 | cout << endl; 250 | if (confirm()) 251 | home(); 252 | else 253 | return; 254 | } 255 | void app::bfs() 256 | { 257 | system("cls"); 258 | cout << "\n--------------------------^-^------------------------------\n"; 259 | if (a._dem_lien_thong() == 1) 260 | { 261 | cout << "Ket qua: "; 262 | a.BFS(); 263 | cout << "\nTac vu thanh cong!\n"; 264 | } 265 | else 266 | cout << "Do thi khong lien thong.\nHuy lenh BFS!\n"; 267 | cout << "\n--------------------------^-^------------------------------\n"; 268 | cout << endl; 269 | if (confirm()) 270 | home(); 271 | else 272 | return; 273 | } 274 | void app::dfs() 275 | { 276 | system("cls"); 277 | cout << "\n--------------------------^-^------------------------------\n"; 278 | cout << "Ket qua: "; 279 | a._DFS(); 280 | cout << "\n--------------------------^-^------------------------------\n"; 281 | cout << endl; 282 | if (confirm()) 283 | home(); 284 | else 285 | return; 286 | } 287 | void app::dijkstra() 288 | { 289 | system("cls"); 290 | cout << "\n--------------------------^-^------------------------------\n"; 291 | if (a._dem_lien_thong() == 1) 292 | { 293 | a.dijkstra(); 294 | cout << "Tac vu thanh cong!\n"; 295 | } 296 | else 297 | cout << "Do thi khong lien thong.\nHuy lenh tim kiem!\n"; 298 | cout << "\n--------------------------^-^------------------------------\n"; 299 | cout << endl; 300 | if (confirm()) 301 | home(); 302 | else 303 | return; 304 | } 305 | void app::home() 306 | { 307 | system("cls"); 308 | if (cnt) 309 | { 310 | cout << "\n\t---------------------^-^---------------------\n"; 311 | cout << "\t|\t Danh sach tac vu. |\n"; 312 | cout << "\t---------------------------------------------\n"; 313 | cout << "\t|\t1. Nhap do thi tu file. |\n"; 314 | cout << "\t|\t2. Nhap moi file do thi tu ban phim.|\n"; 315 | cout << "\t|\t3. Thoat. |\n"; 316 | cout << "\t---------------------------------------------\n"; 317 | cout << "Chon tac vu: "; 318 | char n; 319 | cin >> n; 320 | switch (n) 321 | { 322 | case '1': 323 | { 324 | inputFile(); 325 | break; 326 | } 327 | case '2': 328 | { 329 | inputKeyBoard(); 330 | break; 331 | } 332 | case '3': 333 | return; 334 | default: 335 | { 336 | system("cls"); 337 | cout << "\n --------^-^--------\n"; 338 | cout << "Thao tac khong hop le!\n"; 339 | cout << "\n-----------------------------------\n"; 340 | cout << endl; 341 | if (confirm()) 342 | home(); 343 | else 344 | return; 345 | break; 346 | } 347 | } 348 | } 349 | else 350 | { 351 | cout << "\n\t-------------------^-^-------------------\n"; 352 | cout << "\t|\t Danh sach tac vu. |\n"; 353 | cout << "\t-----------------------------------------\n"; 354 | cout << "\t|\t1. Nhap vao do thi moi. |\n"; 355 | cout << "\t|\t2. Ghi do thi ra file. |\n"; 356 | cout << "\t|\t3. Tao do thi con. |\n"; 357 | cout << "\t|\t4. Duyet do thi theo chieu rong.|\n"; 358 | cout << "\t|\t5. Duyet do thi theo chieu sau. |\n"; 359 | cout << "\t|\t6. Tim duong di ngan nhat. |\n"; 360 | cout << "\t|\t7. Thoat. |\n"; 361 | cout << "\t-----------------------------------------\n"; 362 | cout << "Chon tac vu: "; 363 | char n; 364 | cin >> n; 365 | cout << endl; 366 | switch (n) 367 | { 368 | case '1': 369 | { 370 | Input(); 371 | break; 372 | } 373 | case '2': 374 | { 375 | Output(); 376 | break; 377 | } 378 | case '3': 379 | { 380 | generateSubgraphs(); 381 | break; 382 | } 383 | case '4': 384 | { 385 | bfs(); 386 | break; 387 | } 388 | case '5': 389 | { 390 | dfs(); 391 | break; 392 | } 393 | case '6': 394 | { 395 | dijkstra(); 396 | break; 397 | } 398 | case '7': 399 | return; 400 | default: 401 | { 402 | system("cls"); 403 | cout << "\n--------------------------^-^------------------------------\n"; 404 | cout << "Thao tac khong hop le!\n"; 405 | cout << endl; 406 | if (confirm()) 407 | home(); 408 | else 409 | return; 410 | break; 411 | } 412 | } 413 | } 414 | } 415 | void app::end_task() 416 | { 417 | system("cls"); 418 | cout << "\t\t __ __" << endl; 419 | cout << "\t\t ******** ********" << endl; 420 | cout << "\t\t****____________****" << endl; 421 | cout << "\t\t****| Goodbye! |***" << endl; 422 | cout << "\t\t ***------------**" << endl; 423 | cout << "\t\t *************" << endl; 424 | cout << "\t\t *******" << endl; 425 | cout << "\t\t *" << endl; 426 | } 427 | void app::run() 428 | { 429 | home(); 430 | end_task(); 431 | } 432 | #endif --------------------------------------------------------------------------------