Last active
December 29, 2023 09:18
-
-
Save 18520339/3326071750767b72ee4d56f1eb22b88a to your computer and use it in GitHub Desktop.
My study notes 2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# https://stackoverflow.com/questions/7992689/how-to-loop-over-files-in-natural-order-in-bash | |
# https://stackoverflow.com/questions/3211595/renaming-files-in-a-folder-to-sequential-numbers | |
readarray -d '' entries < <(printf '%s\0' *.png | sort -zV) | |
num=10846 | |
for entry in "${entries[@]}"; do | |
new=$(printf "%07d.png" "$num") #07 pad to length of 7 | |
mv -i -- "$entry" "$new" | |
echo "${entry} -> ${new}" | |
let num=num+1 | |
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <vector> | |
using namespace std; | |
class MySorter { | |
public: | |
virtual ~MySorter() { } | |
virtual void thucHien(vector<int> &a, bool tangDan = true) { | |
if (tangDan) thucHien(a, MySorter::soSanhTangDan); | |
else thucHien(a, MySorter::soSanhGiamDan); | |
} | |
protected: | |
static bool soSanhTangDan(int x, int y) { return x > y; } | |
static bool soSanhGiamDan(int x, int y) { return x < y; } | |
virtual void thucHien(vector<int> &a, bool (*soSanh)(int, int)) = 0; | |
}; | |
class MyInterchangeSorter: public MySorter { | |
public: | |
void thucHien(vector<int> &a, bool (*soSanh)(int, int)) { | |
for (int i = 0; i < a.size(); ++i) | |
for (int j = i + 1; j < a.size(); ++j) | |
if (soSanh(a[i], a[j])) { | |
int tam = a[i]; | |
a[i] = a[j]; | |
a[j] = tam; | |
} | |
} | |
}; | |
class MyBubbleSorter: public MySorter { | |
public: | |
void thucHien(vector<int> &a, bool (*soSanh)(int, int)) override { | |
for (int i = 0; i < a.size(); ++i) | |
for (int j = i + 1; j < a.size(); ++j) | |
if (soSanh(a[j - 1], a[j])) { | |
int tam = a[i]; | |
a[i] = a[j]; | |
a[j] = tam; | |
} | |
} | |
}; | |
class DanhSach { | |
private: | |
vector<int> data; | |
public: | |
void nhap() { | |
int n = 0; | |
cout << "Nhap so luong phan tu: "; | |
cin >> n; | |
data.resize(n); | |
for (int i = 0; i < n; ++i) | |
cin >> data[i]; | |
} | |
void hienThi() { | |
for (int &value: data) | |
cout << value << " "; | |
cout << endl; | |
} | |
void sapXep(MySorter *sorter, bool tangDan = true) { | |
sorter->thucHien(data, tangDan); | |
} | |
}; | |
int main() { | |
DanhSach ds; | |
ds.nhap(); | |
ds.hienThi(); | |
ds.sapXep(new MyInterchangeSorter()); | |
ds.sapXep(new MyBubbleSorter()); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Why deep representations?