Jump to content

[C++] Sort pe indici


FnZ
 Share

Recommended Posts

#include <fstream>
#include <map>
#include <vector>
using namespace std;

ifstream cin("sort.in");
ofstream cout("sort.out");

vector < int > v;
map < int, int > m;

void indexSort()
{
    for(int value : v)
        m[value]++;
}

int main()
{
    int x;
    while(cin>>x)
        v.push_back(x);

    indexSort();

    for(auto it = m.begin(); it != m.end(); it++)
        while(it->second--)
            cout<<it->first<<" ";
    cin.close();
    cout.close();
    return 0;
}

Este apropiat ca si complexitate de timp si eficienta ca sortul din alghoritm.h, intrebari in PM sau in acest topic, faceti-va de cap cu el :). Sortul acesta poate fi implementat chiar si in PAWN pentru cei curiosi asa ca daca aveti sortari de facut puteti sa il luati cu incredere pe acesta.

 

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
 Share

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.