int main()
{
    MyMap *mymap = new MyMap();
    vector<int> *sum_vec;
    const Key *key;
    int len;
    int p[MaxLen];
    srand( unsigned(time(NULL)));
    for(int c = 0; c < MaxNum; ++c)
    {
        len = rand() % MaxLen + 1;
        int sum = 0;
        for(int i = 0; i < len; ++i)
        {
            p[i] = rand() % MaxNum;
            sum += p[i];
        }
        key = new Key(p, len);
        sum_vec = new vector<int>();
        sum_vec->push_back(sum);
        mymap->insert(make_pair(*key, sum_vec));
        delete key;
    }
    for(MyMap::iterator it = mymap->begin(); it != mymap->end(); ++it)
    {
        delete it->second;
    }
    delete mymap;
    return 0;
}
Exemplo n.º 2
0
int main(int argc, char * argv[]) {
    if (argc == 0) {
        cout << "usage: " << argv[0] << "[File1 [File2 [File3 [...]]]]" << endl;
    }
    for (int i = 1; i < argc; i++) {
        cout << "File: " << argv[i] << endl;
        printNames(argv[i]);

        MyMap::iterator it = names.begin();
        while (it != names.end()) {
            //cout << it->first << ": " << it->second << endl;
            sortiert.push_back(it);
            it++;
        }
        //partial_sort (sortiert.begin(), sortiert.bein() + 20, sortiert.end(), mySort);
        partial_sort (sortiert.begin(), sortiert.begin() + 20, sortiert.end(), myObject);

        size_t c = 0;
        for (MyVec::iterator it = sortiert.begin(); it != sortiert.end() && c < 20; it++, c++) {
            cout << (*it)->first << ": " << (*it)->second << endl;
        }
        cout << "==============================" << endl;

        names.clear();
    }
}
Exemplo n.º 3
0
bool Test_STL()
{
    TTRACE(_T("====================================================="));
    typedef std::map<int, char> MyMap;
    MyMap map;
    map.insert(std::make_pair(1, 'A'));
    map.insert(std::make_pair(2, 'B'));
    std::for_each(map.begin(), map.end(), pair_second(Printer()));
    std::for_each(map.begin(), map.end(), pair_second(&Print));

    return true;
}
Exemplo n.º 4
0
/*
 *  Method that determines the colors of silhouettes and background
 *
 *  @param  imageMatrix 2d array that contains color's
 *  @param  width The width of the image
 *  @param  height The height of the image
 *  @param  backgroundColor Variable that indicate background color
 */
void SilCounter::identifyColors(int** imageMatrix, int width, int height,int& backgroundColor){
    // map with key color and value amount of pixels with this color
    MyMap<int,int> colorFreq;

    // walk through 2d array and fill the map
    for(int i = 0; i < height; i++){
        for(int j = 0; j < width; j++){
            colorFreq[imageMatrix[i][j]]++;
        }
    }

    // variables that will contain two most frequent colors
    int mostFreqFirst[2] = {0, 0};
    int mostFreqSecond[2] = {0, 0};

    // searching for two most frequent colors
    for(MyMap<int,int>::iterator it = colorFreq.begin(); it != colorFreq.end(); it++){
        if(it.node->value > mostFreqFirst[1]){
            mostFreqFirst[0] = it.node->key;
            mostFreqFirst[1] = it.node->value;
        }
    }
    for(MyMap<int,int>::iterator it = colorFreq.begin(); it != colorFreq.end(); it++){
        if((it.node->key > mostFreqSecond[1]) && (it.node->key != mostFreqFirst[0] )){
            mostFreqSecond[0] = it.node->key;
            mostFreqSecond[1] = it.node->value;
        }
    }

    // find average between most frequent colors
    int averageValue = (mostFreqFirst[0] + mostFreqSecond[0]) / 2;

    // set all colors that is lower then average to qrequent color with lower index to 0 and vice versa
    for(int i = 0; i < height; i++){
        for(int j = 0; j < width; j++){
            imageMatrix[i][j] < averageValue ? imageMatrix[i][j] = 0 : imageMatrix[i][j] = 1;
        }
    }

    // check the perimeter of the image to identify pixels with what value are more often
    // it will be a background color
    int zeroCounter = 0;
    int oneCounter = 0;

    // checking upper and lower bounds
    for(int i = 0; i < width; i++){
        imageMatrix[0][i] ? oneCounter++ : zeroCounter++;

        imageMatrix[height-1][i] ? oneCounter++ : zeroCounter++;
    }

    // checking sides
    for(int i = 0; i < height; i++){
        imageMatrix[i][0] ? oneCounter++ : zeroCounter++;

        imageMatrix[i][width-1] ? oneCounter++ : zeroCounter++;
    }
    // set background color
    if(oneCounter > zeroCounter ){
        backgroundColor = 1;
    }
}
Exemplo n.º 5
0
void display(MyMap<string, int>& months) {
    MyMap<string, int>::iterator it;
    for (it = months.begin(); it != months.end(); it++)
        cout << it->first << "->" << it->second << endl;
    cout << endl;
}