Разработка программы для создания списка и обработки данных студентов, страница 11

       {

        ed=new educational;

        if(ed)

          {

 ed-> proffs =new profession;

 ed-> education =new address;

            in_file >> str;

            ed->division =strdup(str);  

            in_file >> str;

            ed->direction =strdup(str);

            in_file >> str;

            ed->name =strdup(str);

            in_file >>ed->amount ;

            in_file >>ed->education->post_index;

                                 in_file >> str;

            ed->education -> city=strdup(str);

            in_file >> str;

            ed->education -> street=strdup(str);

                                 in_file >>ed->education -> house;

            in_file >> str;

            ed->proffs -> name=strdup(str);

                                 in_file >> str;

            ed->proffs -> from=strdup(str);

            in_file >>ed->proffs -> competition;          

            in_file >>ed->proffs ->size_pay;

            if(end==NULL)

              {

                begin=ed;

                ed->previous=NULL;

              }

                      else

              {

                ed->previous=end;

                end->next=ed;

                    }

            ed->next=NULL;

            end=ed;

          }

        else

          {

            cout << "memory not enough!"<<endl;

            wait_key();

            break;

          }

       }

   }

 else

   {

    cout << "File not find!" << endl;

    wait_key();

   }

 in_file.close();

 delete []str;

}

//obmen mestami 2 sosednih elementov

int swap_element(educational* ed1, educational* &end, educational* &begin)

{

 educational *ed2=ed1->next;               //polychit' sled. element

 educational *w_next;

 educational *w_previous;

 if(ed1&&ed2&&end&&begin)              //esli vse elemntu syshestvyyt

   {

     if(ed1==begin)                      //obedt' krainii slychai

        begin=ed2;                       //ed1-1-ui element

     if(ed2==end)                        //ili ed2-poslednii element

        end=ed1;

     w_next=ed2->next;                   //preobrazovanie svyazei

     w_previous=ed1->previous;

     ed1->next=w_next;

     ed2->previous=w_previous;

     ed1->previous=ed2;

     ed2->next=ed1;

     if(ed1->next)

        ed1->next->previous=ed1;

     if(ed2->previous)

        ed2->previous->next=ed2;

     return 0;                             //i vozvrat 0

   }

 else                                      //inache vuhod s 1

     return 1;

}

//sortirovka po city

void orend_of_city(educational* &end, educational* &begin)

{

 educational *end_orend=NULL;

 educational *current;

 if(end&&begin)

   {

     while(begin->next!=end_orend)

       {

         current=begin;

         while((current->next!=end_orend))

           {

             if(strcmp(current->education -> city,current->next->education -> city)>=0)

                swap_element(current,end,begin);

             else

                current=current->next;

           }

         if(!current->next)   end_orend=end;

         else

            end_orend=end_orend->previous;

       }

   }

}

//sortirovka postreet

void orend_of_street(educational* &end, educational* &begin)

{

 educational *end_orend=NULL;

 educational *current;

 if(end&&begin)

   {

     while(begin->next!=end_orend)         //proites' stol'ko raz chto bu

       {

         current=begin;                    //daje samui krainii mog vstat' na pervoe mesto

         while((current->next!=end_orend)) //za odin takoi cikl elementu mogyt peredvigat'sya

           {                               //tol'ko na odno mesto