Главная страница


ru.algorithms

 
 - RU.ALGORITHMS ----------------------------------------------------------------
 From : Yuri Burger                          2:468/85.3     20 Dec 2001  21:50:53
 To : All
 Subject : MildAlg FAQ: 10/12
 -------------------------------------------------------------------------------- 
 
 
 
 [ю]ДДДДДДДД Begin 10 ДДДДДДД
         long   N;       // количество пар
         IM();
         IM(IM *s);
         IM(IM& a);
         ~IM();
         void Set(IM *s);
         void   Clear();
         int    SetFromStr(char *str);
         void   sPrint(char *s);
         void   Sort();
         double GetMin();
         double GetMax();
         int    LoadFromFile(const char *filname);
         int    SaveToFile(const char *filname);
         IM  operator + (const IM &s);           // сложение
         IM  operator * (const IM &s);           // умножение
         void Print();                           // вывод
         Atom *FindAtom(double x);               // поиск элемента
         void   SetAtom(double  x,double  m);    // установить с заменой
         void SetAtom(Atom *s);
         void NewAtom(double x,double m);        // добавить новый
         void NewAtom(Atom *s);
 // если add==1 то элемент будет создан (объединение)
 // если add==0 то не будет создан (пересечение)
         void SetMinAtom(double x,double m,char add);
         void SetMaxAtom(double x,double m,char add);
         IM &operator = (const IM &s);
         IM &operator = (const Atom &s);
         IM  operator | (const IM &s);                  // объединение
         IM  operator & (const IM &s);                  // пересечение
         IM  operator ! ();                             // дополнение
         IM  operator - (const IM &s);                  // разность
         IM  operator * (double n);                     // умнож. на число
 };
 
 // модуль LEXAN.CPP
 
 #include "stdafx.h"
 #include "LexAn.h"
 LexAn::LexAn(char *str){
   SrcStr=str;
   curpos=0;
 };
 int LexAn::GetLex(char *resstr){
   static char c;
   while(1){
     switch(SrcStr[curpos++]){
       case 0:return(THE_END);
       case '{':return(OBRACE_);
       case '}':return(CBRACE_);
       case '/':return(SLASH_);
       case '<':return(LESS_);
       case '>':return(MORE_);
       case ',':return(COMMA_);
       case 9:
       case 13:
       case 10:
       case ' ':break;
       default:{
         c=SrcStr[curpos-1];
         if(((c>='0')&&(c<='9'))||(c=='.')){
           static int t;t=0;
           do{
             resstr[t++]=c;
             c=SrcStr[curpos++];
           }while(((c>='0')&&(c<='9'))||c=='.');
           curpos--;
           resstr[t]=0;
           //resint=atol(resstr);
           return(NUMBER_);
         }else
           return(ERROR_);
       };
     };
   };
 };
 int LexAn::GetCurPos(){
   return(curpos);
 };
 
 // модуль ILIB.CPP
 
 #include "stdafx.h"
 #include <math.h>
 #include <stdlib.h>
 #include <stdio.h>
 #include "ILib.h"
 Atom::Atom()
 {
         X=0;
         M=0;
 }
 Atom::Atom(double x,double m)
 {
         X=x;
         M=m;
 }
 Atom::Atom(Atom *a)
 {
         X=a->X;
         M=a->M;
 }
 Atom::~Atom()
 {
 }
 void Atom::Print()
 {
         printf("<%g/%g>",X,M);
 }
 IM::IM()
 {
         A=NULL;
         N=0;
 }
 IM::IM(IM *s)
 {
         long t;
         N=s->N;
         A=(Atom **)calloc(N,sizeof(Atom *));
         for(t=0;t<N;t++)
         {
                 A[t]=new Atom(s->A[t]);
         }
 }
 IM::IM(IM& a)
 {
         A=NULL;
         N=0;
         Set(&a);
 };
 void IM::Set(IM *s)
 {
         long t;
         if(A!=NULL)
         {
                 for(t=0;t<N;t++)
                 {
                         delete A[t];
                 }
                 free(A);
         }
         N=s->N;
         A=(Atom **)calloc(N,sizeof(Atom *));
         for(t=0;t<N;t++)
         {
                 A[t]=new Atom(s->A[t]);
         }
 }
 IM::~IM()
 {
         if(A!=NULL)
         {
                 for(long t=0;t<N;t++)
                 {
                         delete A[t];
                 }
                 free(A);
         }
 }
 void IM::Print()
 {
         printf("{");
         for(long t=0;t<N;t++)
         {
                 A[t]->Print();
                 if(t!=N-1)printf(",");
         }
         printf("}");
 }
 Atom *IM::FindAtom(double x)
 {
         for(long t=0;t<N;t++)
         {
                 if(A[t]->X==x)return A[t];
         }
         return NULL;
 }
 void IM::SetAtom(double x,double m)
 {
         Atom *a=FindAtom(x);
         if(a!=NULL)
         {
                 a->M=m;
         }
         else
         {
                 N++;
                 A=(Atom **)realloc(A,N*sizeof(Atom *));
                 A[N-1]=new Atom(x,m);
         }
 }
 void IM::SetAtom(Atom *s)
 {
         Atom *a=FindAtom(s->X);
         if(a!=NULL)
         {
                 a->M=s->M;
         }
         else
         {
                 N++;
                 A=(Atom **)realloc(A,N*sizeof(Atom *));
                 A[N-1]=new Atom(s);
         }
 }
 void IM::NewAtom(double x,double m)
 {
         N++;
         A=(Atom **)realloc(A,N*sizeof(Atom *));
         A[N-1]=new Atom(x,m);
 }
 void IM::NewAtom(Atom *s)
 {
         N++;
         A=(Atom **)realloc(A,N*sizeof(Atom *));
         A[N-1]=new Atom(s);
 }
 void IM::SetMinAtom(double x,double m,char add)
 {
         Atom *a=FindAtom(x);
         if(a!=NULL)
         {
                 if(a->M>m)a->M=m;
         }
         else
         {
                 if(add==1)
                 {
                         N++;
                         A=(Atom **)realloc(A,N*sizeof(Atom *));
                         A[N-1]=new Atom(x,m);
                 }
         }
 }
 void IM::SetMaxAtom(double x,double m,char add)
 {
         Atom *a=FindAtom(x);
         if(a!=NULL)
         {
                 if(a->M<m)a->M=m;
         }
         else
         {
                 if(add==1)
                 {
                         N++;
                         A=(Atom **)realloc(A,N*sizeof(Atom *));
                         A[N-1]=new Atom(x,m);
                 }
         }
 }
 IM &IM::operator = (const IM &s)
 {
         long t;
         if(A!=NULL)
         {
                 for(t=0;t<N;t++)
                 {
                         delete A[t];
                 }
                 free(A);
         }
         N=s.N;
         A=(Atom **)calloc(N,sizeof(Atom *));.
 [ю]ДДДДДДДД End 10   ДДДДДДД
                                                  Kрюгер.
 ---
  * Origin: А хто тут есть, у кого есть за что поесть? (2:468/85.3)
 
 

Вернуться к списку тем, сортированных по: возрастание даты  уменьшение даты  тема  автор 

 Тема:    Автор:    Дата:  
 MildAlg FAQ: 10/12   Yuri Burger   20 Dec 2001 21:50:53 
Архивное /ru.algorithms/23173c224f4f.html, оценка 3 из 5, голосов 10
Яндекс.Метрика
Valid HTML 4.01 Transitional