0

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;
    }
    
}
8
  • Can you be bit more specific than, "it's not working"? Commented Nov 28, 2022 at 15:45
  • 1
    Any particular reason for not using std::sort? Commented Nov 28, 2022 at 15:46
  • It seems that you do not read the CSV file correctly. Because you just read until the first '|' from the file. Can you please kindly add the text-file structure, maybe one line as an example and the definition of your struct "Details"? Commented Nov 28, 2022 at 15:52
  • 1
    @MubMalik: Code is best placed into your question rather than comments. I suggest you edit your question and then delete your comment. Commented Nov 28, 2022 at 16:48
  • 1
    '...It is giving error' -- Please be specific on the errors you are getting. On the side, you are storing number_of_employees as strings right now, so any sorting applied on them will be done lexicographically(likely not what you wanted). Commented Nov 28, 2022 at 17:06

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.