voidaddEdge(vector<node*> &v, int e1, int e2){ v[e1]->next.insert(v[e2]); v[e2]->next.insert(v[e1]); }
voiddfs(vector<bool> &flag, node* root){ if (root == nullptr) return; cout << root->data << " "; flag[root->data] = false; for (auto it : root->next) { if (flag[it->data]) dfs(flag, it); } }
intmain(){ int m, n; cin >> m >> n; vector<node*> v(m); for (int i = 0; i < m; ++i) v[i] = new node{i, {}}; for (int i = 0; i < n; ++i) { int e1, e2; cin >> e1 >> e2; addEdge(v, e1, e2); }
voiddown_update(vector<int> &v, int i, int n){ int index = i; while (i*2 <= n) { if (v[i*2] < v[i]) index = i*2; if (i*2+1 <=n && v[i*2+1] < v[index]) index = i*2+1; if (index == i) break; swap(v[i], v[index]); i = index; } }
voidbuild_heap(vector<int> &v, int n){ for (int i = n/2; i >= 1; --i) { down_update(v, i, n); } }
intmain(){ int n; cin >> n; vector<int> v(n+1); v[0] = 0; for (int i = 1; i <= n; ++i) cin >> v[i]; build_heap(v, n); for_each(v.begin()+1, v.end(), [] (int i)-> void {cout << i << " ";}); return0; }
voidui_sort(vector<int> &arr, int n){ for (int i = 1; i < n; ++i) { if (arr[i] < arr[0]) swap(arr[0], arr[i]); } for (int i = 2; i < n; ++i) { int j = i; while (arr[j] < arr[j-1]) { swap(arr[j], arr[j - 1]); --j; } } }
intmain(){ int n; cin >> n; vector<int> v(n); for (int i = 0; i < n; ++i) cin >> v[i]; ui_sort(v, n); for (auto it : v) cout << it << " "; return0; }