Thread: Listing Scores in descending order, by using the selection sort

  1. #1
    Registered User
    Join Date
    Oct 2011
    Posts
    23

    Listing Scores in descending order, by using the selection sort

    Hello. This is what in my .txt document.

    Code:
    Lab  1: 10
    Lab  2: 18
    Lab  3: 22
    Lab  4: 19
    Lab  5: 14
    Lab  6: 16
    Lab  7: 18
    Lab  8: 18
    Exam 1: 65
    Exam 2: 42
    I would like to list those number in descending order without changing which test it is:

    Let say Lab 1 is 10 points. After listing it in descending order, it would still be Lab 1: 10.

    The output would look like this for example:

    Lab scores in sorted order:

    22 19 18 18 18 16 14 10


    How would I go about doing this?



    My current code:

    Code:
    #include <stdlib.h>
    #include <stdio.h>
    #include <iostream>
    #include <ctype.h>
    #define MAX 8
    
    
    void main (void);
    void function1 (void);
    void function2 (void);
    
    void main (void)
    {
        function1();
    }
    
    
    void function1 (void)
    {
        FILE *in;
        char var;
        float lab [];
        float test [];
    
        if (( in =  fopen ("grades.txt", "r")) == NULL)
        {
            printf ("Error Opening File");
            return;
        }
        
     
        while ((fscanf(in, "%c", &var)) != EOF)
        {
        
            printf ("%c", var);
            if (var == ':')
                fscanf (in, "%f %f %f %f %f %f %f %f %f %f", &lab[1], &lab[2], &lab[3], &lab[4], &lab[5], &lab[6], &lab[7], &lab[8], &test[1], &test[2])
        }
        printf ("\n");
    }

  2. #2
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,318
    Start by writing an implementation of insertion sort.
    Then for the sorting process whenever you determine that values are out of order, swap both the data in the lab and test arrays for whichever index you need to swap.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. three numbers in descending order
    By jackson6612 in forum C++ Programming
    Replies: 3
    Last Post: 05-21-2011, 08:05 AM
  2. Replies: 9
    Last Post: 04-01-2011, 04:13 PM
  3. ascending and descending order
    By ssk in forum C Programming
    Replies: 3
    Last Post: 03-25-2011, 08:03 PM
  4. bubble sort array in acending and descending order
    By kelvin2355 in forum C++ Programming
    Replies: 2
    Last Post: 07-30-2010, 12:23 PM
  5. Can counting sort sort in descending order?
    By Nutshell in forum C Programming
    Replies: 3
    Last Post: 03-06-2003, 09:59 AM