【发布时间】:2015-11-11 03:51:51
【问题描述】:
我有 10 个这样的数组:
#include <stdio.h>
#include <iostream>
#include <cstdlib>
#include <sstream>
using namespace std;
struct person
{
int age, i;
char name[20], dob[20], pob[20], gender[7];
};
int main ()
{
int i = 0;
person person[10];
for (i; i<10; i++)
{
cout << "Please enter your name, date of birth, place of birth, gender, and age, separated by a space.\nFor example, John 1/15/1994 Maine Male 20: ";
scanf("%s %s %s %s %d", &person[i].name, &person[i].dob, &person[i].pob, &person[i].gender, &person[i].age);
printf("%s %s %s %s %d \n", &person[i].name, &person[i].dob, &person[i].pob, &person[i].gender, person[i].age);
}
sort(person)
return 0;
}
如何按年龄对所有这些数组进行排序?年龄是一个整数,从最小到最大?谢谢。
【问题讨论】:
-
你应该使用 std::vector
-
@Mikhail 为什么会这样?
-
@johnny880 与数组相比,它们在空间和时间方面效率更高。
-
@NickyC 好吧,他没有使用矢量,所以它可能不是重复的。虽然他应该使用矢量...
标签: c++ arrays sorting c++11 int