C++ exercises solutions: sort the records

C++ structure exercise: sort the records

Step 11: Defining the sort(struct student st[], int itemcount) function to sort the records in ascending order by total scores. For the sort technique we use bubble sort algorithm.

void bubblesort(struct student dataset[], int n)
  int i, j;
  for (i = 0; i < n; i++)
    for (j = n - 1; j > i; j--)
      if (dataset[j].total < dataset[j - 1].total )
         student temp = dataset[j];
         dataset[j] = dataset[j - 1];
         dataset[j - 1] = temp;



baby comment




This website intents to provide free and high quality tutorials, examples, exercises and solutions, questions and answers of programming and scripting languages:
C, C++, C#, Java, VB.NET, Python, VBA,PHP & Mysql, SQL, JSP, ASP.NET,HTML, CSS, JQuery, JavaScript and other applications such as MS Excel, MS Access, and MS Word. However, we don't guarantee all things of the web are accurate. If you find any error, please report it then we will take actions to correct it as soon as possible.