Answer to Question #284083 in C++ for Umar

Question #284083

You have been provided with a data of 50 different students .

The data consist of  following Fields 

Student . name

Roll no

Semester

Session 

The data is placed in a highly random order you have to use one of the divide and conquer approach based sorting algorithm .

To sort this data your output will be based on two types of data 

No.1 

Liste 0f randomly displayed information 

No 2

List of sorted information on the base of rollno.

using c++ structural programing


1
Expert's answer
2022-01-02T02:20:57-0500
#include <iostream>

void countSort(int upperBound, int lowerBound, std::vector<int> numbersToSort) //lower and upper bounds of numbers in vector
{
  int range = upperBound - lowerBound;                  //create a range large enough to get every number between the min and max
  std::vector<int> counts (range);                      //initialize of counts of the size of the range
  std::fill(counts.begin(), counts.end(), 0);           //fill vector of zeros
  
  for (int i = 0; i < numbersToSort.size(); i++)
  {
      int index = numbersToSort[i] - lowerBound; //For example, if 5 is the lower bound and numbersToSort[i] is 5. index will be 0 and the counts[index]+= 1; //count of 5 will be stored in counts[0]
  }
  
  std::cout << counts << std::endl;
} 

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog