Register for your free account! | Forgot your password?

Go Back   elitepvpers > Coders Den > C/C++
You last visited: Today at 00:02

  • Please register to post and access all features, it's quick, easy and FREE!

Advertisement



[help] Sorting structures...??

Discussion on [help] Sorting structures...?? within the C/C++ forum part of the Coders Den category.

Reply
 
Old   #1
 
elite*gold: 0
Join Date: Apr 2012
Posts: 370
Received Thanks: 20
[help] Sorting structures...??

Well, how can i sort structers according to one element of them??

Code:
      struct PersonalData
        {
               int
                char *FirstName;
                char *LastName;
                char *Birthday;  // in the format of 12/30/1978
                int  id;
        };


        PersonalData PersonOne;

        // Populate PersonOne with data
        PersonOne.FirstName = "John";
        PersonOne.LastName = "Doe";
        PersonOne.Birthday = "12/30/1978";
        PersonOne.id = 5;

        // Populate PersonTwo with data
        PersonTwo.FirstName = "Matt";
        PersonTwo.LastName = "Thompson";
        PersonTwo.Birthday = "15/20/1958";
        PersonTwo.id = 3;
so lets say i'd like to sort them according to the 'id' element of the structures, how do i do it??
Hikarim is offline  
Old 12/09/2012, 23:39   #2
 
elite*gold: 0
Join Date: May 2010
Posts: 793
Received Thanks: 268
you put your structs in a std::list and use list.sort

you should also use std::string (or wstring) instead of char*.
nkkk is offline  
Old 12/20/2012, 16:35   #3



 
+Yazzn's Avatar
 
elite*gold: 420
Join Date: Jan 2012
Posts: 1,030
Received Thanks: 982
qsort - C++ Reference

But rather use std::list.
+Yazzn is offline  
Reply


Similar Threads Similar Threads
another java problem about sorting a scheduling algorithm
09/28/2012 - General Coding - 2 Replies
i've tried to use 3 arrays which are System.out.println("enter number of process: "); int process = in.nextInt(); String name = new String; int ArrivalT = new int; int BurstT = new int; and then i've used for loop for inputs of name, BT and AT.
JAVA problem array sorting
09/28/2012 - General Coding - 1 Replies
i use three arrays where in System.out.println("Enter number of process: "); int process = in.nextInt(); String name = new String; int age = new int; double income = new double; bla bla bla so basically i used three arrays and a for loop and the outcome is this. (note: this is a user input)
[Tool] LoLEtal Sorting
03/29/2012 - League of Legends - 0 Replies
This is a little program I made to sort the accounts you want to bot. It compiles the list of all the completed accounts and accounts to check which ones are done or not and distribute the unfinished accounts among the bots. http://www.mediafire.com/?yyx0f8kfhbybkw1 Instructions: 1. Put the jar file in the folder with all the bots, like picture below; http://dl.dropbox.com/u/4962068/one.png 2. Run jar file, and it will tell you how many accounts unfinished;...
structures of files ....
03/04/2012 - CO2 Private Server - 0 Replies
i wanna make a new map , i have already made the design but i want to know what are the structures of .dmap and .pul files and how to creat 'em thanks in advance
Sorting Everything out
04/22/2009 - Dekaron - 2 Replies
ok i had a friend who helped me put in my first hackes in when i played 2moons but now he got banned and dont play no more so i need help finding where things go i have unpacked dekaron, gameguardkiller and the laucher for it and the CE, but the only problem im having is that i cant seem to figure out where things go do i put the unpacked dekaron in the bin and the gameguardkiller in the gameguard folder? thats all im cofnused with if u have anyhting that can help me plzz post and tell me where...



All times are GMT +2. The time now is 00:02.


Powered by vBulletin®
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Support | Contact Us | FAQ | Advertising | Privacy Policy | Terms of Service | Abuse
Copyright ©2024 elitepvpers All Rights Reserved.