![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
いろいろなテクニック.Nucleo と DISCO-F746 用.
Dependencies: Array_Matrix mbed
MySort.hpp@0:bb939e0bc6e2, 2017-10-15 (annotated)
- Committer:
- MikamiUitOpen
- Date:
- Sun Oct 15 11:41:48 2017 +0000
- Revision:
- 0:bb939e0bc6e2
- Child:
- 1:bbb9f0c3e523
1
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
MikamiUitOpen | 0:bb939e0bc6e2 | 1 | #include "mbed.h" |
MikamiUitOpen | 0:bb939e0bc6e2 | 2 | #include <algorithm> |
MikamiUitOpen | 0:bb939e0bc6e2 | 3 | #include <string> |
MikamiUitOpen | 0:bb939e0bc6e2 | 4 | |
MikamiUitOpen | 0:bb939e0bc6e2 | 5 | void MySort() |
MikamiUitOpen | 0:bb939e0bc6e2 | 6 | { |
MikamiUitOpen | 0:bb939e0bc6e2 | 7 | printf("\r\n\"MySort\" の開始\r\n"); |
MikamiUitOpen | 0:bb939e0bc6e2 | 8 | |
MikamiUitOpen | 0:bb939e0bc6e2 | 9 | // 配列を昇順にソートする |
MikamiUitOpen | 0:bb939e0bc6e2 | 10 | const int N = 6; |
MikamiUitOpen | 0:bb939e0bc6e2 | 11 | string data0[N] = {"const", "Printf", "Int", "for", "array", "Vector"}; |
MikamiUitOpen | 0:bb939e0bc6e2 | 12 | printf("ソート前:\r\n"); |
MikamiUitOpen | 0:bb939e0bc6e2 | 13 | for (int n=0; n<N; n++) |
MikamiUitOpen | 0:bb939e0bc6e2 | 14 | printf(" %s\r\n", data0[n].c_str()); |
MikamiUitOpen | 0:bb939e0bc6e2 | 15 | |
MikamiUitOpen | 0:bb939e0bc6e2 | 16 | string *data1 = new string[N]; |
MikamiUitOpen | 0:bb939e0bc6e2 | 17 | for (int n=0; n<N; n++) data1[n] = data0[n]; |
MikamiUitOpen | 0:bb939e0bc6e2 | 18 | sort(data1, data1+N); // 配列 |
MikamiUitOpen | 0:bb939e0bc6e2 | 19 | printf("ソート後:\r\n"); |
MikamiUitOpen | 0:bb939e0bc6e2 | 20 | for (int n=0; n<N; n++) |
MikamiUitOpen | 0:bb939e0bc6e2 | 21 | printf(" %s\r\n", data1[n].c_str()); |
MikamiUitOpen | 0:bb939e0bc6e2 | 22 | |
MikamiUitOpen | 0:bb939e0bc6e2 | 23 | printf("\"MySorth\" の終了\r\n"); |
MikamiUitOpen | 0:bb939e0bc6e2 | 24 | delete [] data1; |
MikamiUitOpen | 0:bb939e0bc6e2 | 25 | } |
MikamiUitOpen | 0:bb939e0bc6e2 | 26 | |
MikamiUitOpen | 0:bb939e0bc6e2 | 27 | // array, vector を昇順にソートする |
MikamiUitOpen | 0:bb939e0bc6e2 | 28 | // 「array」,「vector」 |
MikamiUitOpen | 0:bb939e0bc6e2 | 29 | //array<int,N> ar; |
MikamiUitOpen | 0:bb939e0bc6e2 | 30 | //vector<int> v; |
MikamiUitOpen | 0:bb939e0bc6e2 | 31 | //sort(ar.begin(), ar.end()); // array |
MikamiUitOpen | 0:bb939e0bc6e2 | 32 | //sort(v.begin(), v.end()); // vector |