поиск по нескольким параметрам
Несколько структур такого типа связаны в двухсвязный список.
Требуется осуществить поиск по этому списку.
Функция имет вид:
Код:
void search(char *par1 = NULL, char *par2 = NULL,char *par3 = NULL )
Заранее число ненулевых параметров неизвестно.
Код:
if(curent->next == 0) return;
else curent = curent->next;
continue;
else curent = curent->next;
continue;
Код:
void HumanSearch(human * curent,
char * name = NULL,
char * _2name = NULL,
char * fathername = NULL,
char * adress = NULL,
char * workplace = NULL,
char * telephone = NULL,
char * sex = NULL,
char * age = NULL ){
for ( ; ; ){
if(name != NULL){
if(name != curent->name){
if(curent->next == 0) return;
else curent = curent->next;
continue;
}
}
if(_2name != NULL){
if(_2name != curent->_2name){
if(curent->next == 0) return;
else curent = curent->next;
continue;
}
}
if(fathername != NULL){
if(fathername != curent->fathername){
if(curent->next == 0) return;
else curent = curent->next;
continue;
}
}
if(adress != NULL){
if(adress != curent->adress){
if(curent->next == 0) return;
else curent = curent->next;
continue;
}
}
if(workplace != NULL){
if(workplace != curent->workplace){
if(curent->next == 0) return;
else curent = curent->next;
continue;
}
}
if(telephone != NULL){
if(telephone != curent->telephone){
if(curent->next == 0) return;
else curent = curent->next;
continue;
}
}
if(sex != NULL){
if(sex != curent->sex){
if(curent->next == 0) return;
else curent = curent->next;
continue;
}
}
if(age != NULL){
if(age != curent->age){
if(curent->next == 0) return;
else curent = curent->next;
continue;
}
}
curent->printHuman();
if (curent->next == 0) return;
curent = curent->next;
}
}
char * name = NULL,
char * _2name = NULL,
char * fathername = NULL,
char * adress = NULL,
char * workplace = NULL,
char * telephone = NULL,
char * sex = NULL,
char * age = NULL ){
for ( ; ; ){
if(name != NULL){
if(name != curent->name){
if(curent->next == 0) return;
else curent = curent->next;
continue;
}
}
if(_2name != NULL){
if(_2name != curent->_2name){
if(curent->next == 0) return;
else curent = curent->next;
continue;
}
}
if(fathername != NULL){
if(fathername != curent->fathername){
if(curent->next == 0) return;
else curent = curent->next;
continue;
}
}
if(adress != NULL){
if(adress != curent->adress){
if(curent->next == 0) return;
else curent = curent->next;
continue;
}
}
if(workplace != NULL){
if(workplace != curent->workplace){
if(curent->next == 0) return;
else curent = curent->next;
continue;
}
}
if(telephone != NULL){
if(telephone != curent->telephone){
if(curent->next == 0) return;
else curent = curent->next;
continue;
}
}
if(sex != NULL){
if(sex != curent->sex){
if(curent->next == 0) return;
else curent = curent->next;
continue;
}
}
if(age != NULL){
if(age != curent->age){
if(curent->next == 0) return;
else curent = curent->next;
continue;
}
}
curent->printHuman();
if (curent->next == 0) return;
curent = curent->next;
}
}
Цикл:
for ( ;curent!=NULL; curent = curent->next)
{
...
}
Сравнение:
if((name!=NULL)&&(strcmp(name, curent->name)!=0))continue;
if((_2name!=NULL)&&(strcmp(_2name, curent->_2name)!=0))continue;
итд.
Спасибо!