结构的时间复杂度

用户名

我在医院管理系统的C ++中使用struct来保存患者记录,并使用它来添加,列出,搜索和删除记录,例如,

struct details{
    char first_name[20];
    char last_name[20];
    int age;
    char gender[7];
    int phone;
    char doc_name[40];
};
details d[100];

void add()
{
   counter++;
   cout<<"\n\t\t\tRECORD NUMBER: "<<counter;
   cout<<"\n\t\t\t1.FIRST NAME: ";
   cin>>d[counter].first_name;
   cout<<"\t\t\t2.LAST NAME: ";
   cin>>d[counter].last_name;
   cout<<"\t\t\t3.AGE: ";
   cin>>d[counter].age;
   cout<<"\t\t\t4.GENDER: ";
   cin>>d[counter].gender;
   cout<<"\t\t\t5.PHONE: ";
   cin>>d[counter].phone;
   cout<<"\t\t\t6.DOCTOR: ";
   cin>>d[counter].doc_name;
   char add_another;
   cout<<"\n Add another record (Y/N)?:  ";
   cin>>add_another;
   if(add_another == 'Y')
     add();
   else
     menu();
}

我想知道使用struct的时间复杂度。使用链接列表或地图或矢量是保存记录的更好选择吗?

托马斯·马修斯

我建议您使用结构向量保存数据。

接下来,我建议您创建std::map用于搜索数据库的文件。该地图将是以下类型:
std::map<key_type, unsigned int>

key_type您要搜索的字段的数据类型在哪里
unsigned int将成为向量的索引。

这些std::map变量称为索引表这使您可以排序并有效地搜索记录,而无需修改数据向量。

另外,如果可以的话,请用替换char *字段std::stringstd::string类型更易于使用,尤其是使用std::vector和时std::map

最好的开发途径是使用现有数据库而不是编写自己的数据库。记住,您有开发和测试的时间。现有数据库已经开发和测试;您只需要访问它们;不发展他们。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章