Mub Malik
Mub Malik

Reputation: 1

How to apply selection sort on a csv file data which is read into a struct based on a specific column?

enter code here I am reading an excel .csv file data to a struct. I am supposed to apply selection sort algorithm to this data on the basis of number of employees and then saving this sorted data into a new .csv file. I have wriiten this code but its not working.

vector<Details> results;
    ifstream inputFile ("C:/Users/Mubashra Zaman/Downloads/organizations-100.csv");
    Details swimmer;
    string line;
    
    while (!inputFile.eof() && getline(inputFile, line, '|'))
    {
        cout << line << "\t";
        stringstream ss(line);
        Details swimmer;
        for (int i = 0; i < 1e4; i++)
        {
            if (ss >> swimmer.index >> swimmer.organization_Id >> 
            swimmer.name >> swimmer.website >> swimmer.country >> 
            swimmer.description>>swimmer.founded>>swimmer.industry
            >>swimmer.number_of_employees)
            {
                results.push_back(swimmer);
            }
        }
        
    }

Selection sort Function:

void selectionSort(Details data[], int size)
{
    for (int startscan = 0; startscan < (size - 1); startscan++) 
    {
        int minindex = startscan;
        string minvalue = data[startscan].number_of_employees;

        for (int index = startscan + 1; index < size; index++)
            if (data[index].number_of_employees < minvalue)
                minvalue = data[minindex = index].number_of_employees;

        Details temp = data[minindex];
        data[minindex] = data[startscan];
        data[startscan] = temp;
    }
    
}

Upvotes: 0

Views: 26

Answers (0)

Related Questions