Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7701585
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T23:01:21+00:00 2026-05-31T23:01:21+00:00

I have a struct typedef struct { int id; string name; string address; string

  • 0

I have a struct

typedef struct  
{ 
    int id;  
    string name;  
    string address;
    string city;  
    // ...
} Customer;

I will have multiple customers so I need to store these structs in some sort of a list and then I need to sort by id. There a probably multiple solutions here and I have a few ideas myself but I am looking for the best solution in terms of performance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T23:01:22+00:00Added an answer on May 31, 2026 at 11:01 pm

    Use the sort provided by the stl algorithms package, example:

    struct Customer {
        int id;
        Customer(int i) : id(i) {}
    };
    
    bool sortfunc(struct Customer i, struct Customer j) {
        return (i.id < j.id);
    }
    
    int main() {
        vector<Customer> customers;
        customers.push_back(Customer(32));
        customers.push_back(Customer(71));
        customers.push_back(Customer(12));
        customers.push_back(Customer(45));
        customers.push_back(Customer(26));
        customers.push_back(Customer(80));
        customers.push_back(Customer(53));
        customers.push_back(Customer(33));
    
        sort(customers.begin(), customers.end(), sortfunc);
    
        cout << "customers:";
        vector<Customer>::iterator it;
        for (it = customers.begin(); it != customers.end(); ++it)
            cout << " " << it->id;
    
        return 1;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a structure typedef struct store { char name[11]; int age; } store;
I have these structs: typedef struct _Frag{ struct _Frag *next; char *seq; int x1;
I have declared the following struct: typedef struct _RECOGNITIONRESULT { int begin_time_ms, end_time_ms; char*
Let's say I have a first structure like this: typedef struct { int ivalue;
I have this struct: #define sbuffer 128 #define xbuffer 1024 typedef struct{ char name[sbuffer];
I have this struct typedef struct grade { char firstName[SIZE]; char lastName[SIZE]; int stuNum;
I have a code: #include <stdio.h> #include <stdlib.h> #include <conio.h> #include <string.h> typedef struct
Ok so I have struct like this typedef struct { float x; float y;
How can we access variables of a structure? I have a struct: typedef struct
I have a struct like this typedef struct bookStruct { char title[80]; char author[80];

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.