Sorting Problem

This is a discussion on Sorting Problem within the C++ Programming forums, part of the General Programming Boards category; Hello there, i am trying to create a league table within a program, the teams points are located within individual ...

  1. #1
    Registered User
    Join Date
    Jul 2010
    Posts
    1

    Sorting Problem

    Hello there, i am trying to create a league table within a program, the teams points are located within individual data structs though. Can anyone help, I want the team with the most points on top , followed by the second most points ect. But i also want to output the team name alongside it.

    Thanks

    Code:
         
    
         cout<<UserTeam.Teamname<<"\t "<<UserTeam.Leaguepoints<<endl;
         cout<<Oppositionteam1.Teamname<<"\t "<<Oppositionteam1.Leaguepoints<<endl;
         cout<<Oppositionteam2.Teamname<<"\t\t "<<Oppositionteam2.Leaguepoints<<endl;
         cout<<Oppositionteam3.Teamname<<"\t "<<Oppositionteam3.Leaguepoints<<endl;
         cout<<Oppositionteam4.Teamname<<"\t\t "<<Oppositionteam4.Leaguepoints<<endl;
         cout<<Oppositionteam5.Teamname<<"\t "<<Oppositionteam5.Leaguepoints<<endl;
    Userteam and Oppoisition teams are individual data structs.

    I'm a new programmer so go easy

  2. #2
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,675
    In a nutshell:
    1. Create a container to store data for your individual teams (an array or vector of structs for example).
    2. Define operator< (less than) for your team structs.
    3. Call the std::sort function.
    4. Print contents of newly sorted container from start to finish.

    Probably less detail than you want... but lets see what you can make of that as a starting point.
    I used to be an adventurer like you... then I took an arrow to the knee.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Sorting problem?
    By audinue in forum C Programming
    Replies: 5
    Last Post: 01-06-2009, 01:16 PM
  2. Array Sorting problem
    By ___________ in forum C++ Programming
    Replies: 4
    Last Post: 07-22-2008, 12:17 AM
  3. What is problem about the sorting?
    By Mathsniper in forum C Programming
    Replies: 2
    Last Post: 04-17-2005, 07:00 AM
  4. Sorting text file problem...
    By John-m in forum C Programming
    Replies: 3
    Last Post: 10-01-2002, 04:51 PM
  5. Sorting array output problem
    By Unregistered in forum C Programming
    Replies: 4
    Last Post: 02-19-2002, 12:44 PM

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