how to sort the scores(small to large)

This is a discussion on how to sort the scores(small to large) within the C++ Programming forums, part of the General Programming Boards category; Acutally i have 10 good scores: 23 5 87 29 87 0 100 55 33 23 how can i sort ...

  1. #1
    Registered User
    Join Date
    Nov 2005
    Posts
    20

    how to sort the scores(small to large)

    Acutally i have 10 good scores:
    23 5 87 29 87 0 100 55 33 23

    how can i sort good score in ascendant order(samll to large)

    here is my code:

    Code:
    void soreScores(ofstream& outdata, int listThree[])
    {
    	int counter;
    	int x = 0;
    
    	outdata << "Sorted good scores:";
    	outdata << endl;
    	 
    	for (counter = 0; counter < 10; counter++)
    	{
    		if (listThree[x] <= listThree[counter])
    		{
    			listThree[x] = listThree[counter];
    			outdata << setw(4) <<listThree[x];
    		}
    	}
    }

  2. #2
    C++ Enthusiast jmd15's Avatar
    Join Date
    Mar 2005
    Location
    MI
    Posts
    532
    Here's an extremely easy way:
    Code:
    #include <iostream>
    #include <algorithm>
    
    using namespace std;
    
    int main()
    {
        int nums[]={24,72,34,11,82,7,25,92,0,10,6};
        for(int i=0;i<11;i++)
        cout<<nums[i]<<" ";
        sort(nums,nums+11);
        cout<<endl<<endl;
        for(int b=0;b<11;b++)
        cout<<nums[b]<<" ";
        cout<<endl;
        system("PAUSE");
        return 0;
    }
    In the example I make an array of numbers, use the sort algorithm, and it's now sorted from smallest to largest.
    Trinity: "Neo... nobody has ever done this before."
    Neo: "That's why it's going to work."
    c9915ec6c1f3b876ddf38514adbb94f0

  3. #3
    Registered User
    Join Date
    Nov 2005
    Posts
    85
    Code:
    void Bubblesort(int arr[],const int size)
    {
              for(int i=size-1;i>0;i--)
              {
                     for(int i=0;i<size;i++)
                     {
                                if(arr[i]>arr[i+1])
                                        swap(arr[i],arr[i+1]);
                      }
               }
    }
    just whipped it up then, try on ur code

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 26
    Last Post: 07-05-2010, 11:43 AM
  2. Replies: 5
    Last Post: 08-02-2008, 07:23 AM
  3. Straight Insertion Sort function problem
    By StaticKyle in forum C++ Programming
    Replies: 6
    Last Post: 05-12-2008, 05:03 AM
  4. recursive sort
    By bethan in forum C Programming
    Replies: 2
    Last Post: 03-06-2005, 08:18 AM
  5. Using quicksort and radix sort for an anagram program
    By RazielX in forum C Programming
    Replies: 2
    Last Post: 05-03-2004, 10:33 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21