いろいろなテクニック.Nucleo と DISCO-F746 用.

Dependencies:   Array_Matrix mbed

MySort.hpp

Committer:
MikamiUitOpen
Date:
2019-04-10
Revision:
1:bbb9f0c3e523
Parent:
0:bb939e0bc6e2

File content as of revision 1:bbb9f0c3e523:

#include "mbed.h"
#include <algorithm>
#include <string>

void MySort()
{
    printf("\r\n\"MySort\" の開始\r\n");

    // 配列を昇順にソートする
    const int N = 6;
    string data0[N] = {"const", "Printf", "Int", "for", "array", "Vector"};
    printf("ソート前:\r\n");
    for (int n=0; n<N; n++)
        printf("    %s\r\n", data0[n].c_str());

//    string *data1 = new string[N];
    string data1[N];    // これでもよい
    for (int n=0; n<N; n++) data1[n] = data0[n];
    sort(data1, data1+N); // 配列
    printf("ソート後:\r\n");
    for (int n=0; n<N; n++)
        printf("    %s\r\n", data1[n].c_str());

    printf("\"MySorth\" の終了\r\n");
//    delete [] data1;  // data1 に new で確保した領域を割り当てない場合は,これは不要
}

// array, vector を昇順にソートする
// 「array」,「vector」
//array<int,N> ar;
//vector<int> v;
//sort(ar.begin(), ar.end()); // array
//sort(v.begin(), v.end()); // vector