p)
{if(i==second_size-1) break; i++;}
while(m_data[j]=0 || accuracy<=8)return(DoubleToString(getDOUBLE(j),accuracy));
else return((string)getDOUBLE(j));
};
void Get(int j,double &recipient){recipient=second_data[j];};
int Resize_second(int j){second_size=j; return(ArrayResize(second_data,second_size));};
int QuickSearch(double element,int beg,int end,Cint2D &index,bool mode=false);
int SearchFirst(double element,int beg,int end,Cint2D &index,bool mode=false);
int SearchLast(double element,int beg,int end,Cint2D &index,bool mode=false);
int SearchGreat(double element,int beg,int end,Cint2D &index,bool mode=false);
int SearchLess(double element,int beg,int end,Cint2D &index,bool mode=false);
void Digits(int digits){accuracy=digits;};
int Digits(){return(accuracy);};
void Sort(Cint2D &index,int beg,int end,bool mode=false)
{
double m_data[];
ArrayResize(m_data,ArraySize(second_data));
for(int i=0;i=second_size){Print("Incorrect end "+__FUNCTION__);return(-1);}
//--- search
if(mode)
{
while(!IsStopped())
{
m=(j+i)>>1;
if(mend || jelement) j=m-1;
else i=m+1;
}
}
else
{
while(!IsStopped())
{
m=(j+i)>>1;
if(mend || j=element)
{
if(mode)
{
while(second_data[index.Ind(pos)]==element)
if(pos--==beg) return(-1);
}
else
{
while(second_data[index.Ind(pos)]>=element)
if(pos++==end) return(-1);
}
}
}
//---
return(pos);
}
//+------------------------------------------------------------------+
//| Method QuickSort. |
//| INPUT: beg - start of sorting range, |
//| end - end of sorting range, |
//| mode - mode of sorting. |
//| OUTPUT: no. |
//| REMARK: no. |
//+------------------------------------------------------------------+
void CDOUBLEArray::QuickSort(double &m_data[],Cint2D &index,int beg,int end,bool mode=0)
{
double p,t; int it;
if(beg<0 || end<0) return;
int i=beg,j=end;
if(mode)
{
while(i>1];
while(ip)
{if(j==0) break; j--;}
if(i<=j)
{
t=m_data[i]; it=index.Ind(i);
m_data[i++]=m_data[j]; index.Ind(i-1,index.Ind(j));
m_data[j]=t; index.Ind(j,it);
if(j==0) break;
else j--;
}
}
if(beg>1];
while(ip)
{if(i==second_size-1) break; i++;}
while(m_data[j]=second_size){Print("Incorrect end "+__FUNCTION__);return(-1);}
//--- search
if(mode)
{
while(!IsStopped())
{
m=(j+i)>>1;
if(mend || jelement) j=m-1;
else i=m+1;
}
}
else
{
while(!IsStopped())
{
m=(j+i)>>1;
if(mend || j=element)
{
if(mode)
{
while(second_data[index.Ind(pos)]==element)
if(pos--==beg) return(-1);
}
else
{
while(second_data[index.Ind(pos)]>=element)
if(pos++==end) return(-1);
}
}
}
//---
return(pos);
}
//+------------------------------------------------------------------+
//| Method QuickSort. |
//| INPUT: beg - start of sorting range, |
//| end - end of sorting range, |
//| mode - mode of sorting. |
//| OUTPUT: no. |
//| REMARK: no. |
//+------------------------------------------------------------------+
void CDATETIMEArray::QuickSort(datetime &m_data[],Cint2D &index,int beg,int end,bool mode=0)
{
datetime p,t; int it;
if(beg<0 || end<0) return;
int i=beg,j=end;
if(mode)
{
while(i>1];
while(ip)
{if(j==0) break; j--;}
if(i<=j)
{
t=m_data[i]; it=index.Ind(i);
m_data[i++]=m_data[j]; index.Ind(i-1,index.Ind(j));
m_data[j]=t; index.Ind(j,it);
if(j==0) break;
else j--;
}
}
if(beg>1];
while(ip)
{if(i==second_size-1) break; i++;}
while(m_data[j]=second_size){Print("Incorrect end "+__FUNCTION__);return(-1);}
//--- search
if(mode)
{
while(!IsStopped())
{
m=(j+i)>>1;
if(mend || j>1;
if(mend || j=0)
{
if(mode)
{
while(second_data[index.Ind(pos)]==element)
if(pos--==beg) return(-1);
}
else
{
while(StringCompare(second_data[index.Ind(pos)],element)>=0)
if(pos++==end) return(-1);
}
}
}
//---
return(pos);
}
//+------------------------------------------------------------------+
//| Method BubbleSort. |
//| INPUT: beg - start of sorting range, |
//| end - end of sorting range, |
//| mode - mode of sorting. |
//| OUTPUT: no. |
//| REMARK: no. |
//+------------------------------------------------------------------+
void CSTRINGArray::BubbleSort(Cint2D &index,int Start,int End,bool maxx=true)
{
int c=0,start=Start,end=End;
if(maxx)
{
do
{
c=0;
int n=start;// correction of start
int k=end;// correction of end
for(int i=start;i
{
int itemp=index.Ind(i+1);
index.Ind(i+1,index.Ind(i));
index.Ind(i,itemp);
k=i;
c++;
}
}
end=k;
if(c==0)break;
c=0;
for(int i=end;i>start;i--)
{
if(StringCompare(second_data[index.Ind(i)],second_data[index.Ind(i-1)])==-1)//<
{
int itemp=index.Ind(i-1);
index.Ind(i-1,index.Ind(i));
index.Ind(i,itemp);
n=i;
c++;
}
}
start=n;
if(IsStopped())break;
}
while(c!=0);
}
else
{
do
{
c=0;
int n=start;// correction of start
int k=end;// correction of end
for(int i=start;istart;i--)
{
if(StringCompare(second_data[index.Ind(i)],second_data[index.Ind(i-1)])==1)//>
{
int itemp=index.Ind(i-1);
index.Ind(i-1,index.Ind(i));
index.Ind(i,itemp);
n=i;
c++;
}
}
start=n;
if(IsStopped())break;
}
while(c!=0);
}
}
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//| call of the file |
//| #include |
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//| class of two-dimensional array |
//+------------------------------------------------------------------+
#define _CHECK0_ Print(__FUNCTION__+"("+(string)i+","+(string)j+")");return;
#define _CHECK_ Print(__FUNCTION__+"("+(string)i+")");return(-1);
#define _FIRST_ first_data[aic[i]]
#define _PARAM0_ array_index.Ind(j),value
#define _PARAM1_ array_index.Ind(j),recipient
#define _PARAM2_ element,beg,end,array_index,mode
//+------------------------------------------------------------------+
class CTable
{
private:
int start_first_size;// initial size or row
int first_size;// row size
int second_size;// columns size
CBASEArray *first_data[];// array-row, heading of array-columns
Cint2D array_index;// two-dimensional array of indexes
int aic[];// array of indexes of columns aic[]-array_index_column[]
ENUM_DATATYPE type_table[];// array of types
void SwitchType(int i);
bool check_type(int i,ENUM_DATATYPE t);// checking if the type of data correspond to the type array
public:
CTable(void){first_size=0;};
~CTable(void);
void variant(int ind){array_index.Variant(ind);};
int variant(){return(array_index.Variant());};
void variantcopy(int rec,int sor){array_index.Variant(rec); array_index.VariantCopy(rec,sor);};
bool Change(int &sor0,int &sor1);// swap columns
bool Insert(int rec,int sor);// insert a column in a specified position with pulling of other columns
int FirstSize(){return(first_size);};
int SecondSize(){return(second_size);};
//--- changing size of a two-dimensional array with changing of all associated information.
void FirstResize(const ENUM_DATATYPE &TYPE[]); // initial division of array
void SecondResize(int j);// second dimension
void PruningTable(int count);// new size of the first dimension, the change is possible within the start size
void CopyTable(CTable *sor,int sec_beg,int sec_end);// copying of one table to another, a new table is created according to the 'sor' sample
void CopyTable(CTable *sor){CopyTable(sor,0,sor.SecondSize()-1);};// copying of one table to another on the entire length of of the second dimension
ENUM_DATATYPE TypeTable(int i){return(type_table[aic[i]]);};// returns the type_table value of the column 'i'
//--- accuracy of printing
void StringDigits(int i,int digits){_FIRST_.Digits(digits);};// setting accuracy of printing of double,datetime (-1 means that accuracy is not set)
int StringDigits(int i){return(_FIRST_.Digits());};// get accuracy of printing of double,datetime (!= -1 means accuracy of output includes seconds)
//--- i - index of the first dimension, j index of the second dimension
//--- setting value
void Set(int i,int j,long value) {if(!check_type(i,TYPE_LONG)) {_CHECK0_} _FIRST_.set(_PARAM0_);};// setting value of i-th row and j-th column
void Set(int i,int j,double value) {if(!check_type(i,TYPE_DOUBLE)) {_CHECK0_} _FIRST_.set(_PARAM0_);};// setting value of i-th row and j-th column
void Set(int i,int j,datetime value) {if(!check_type(i,TYPE_DATETIME)){_CHECK0_} _FIRST_.set(_PARAM0_);};// setting value of i-th row and j-th column
void Set(int i,int j,string value);// setting value of i-th row and j-th column; if the selected column is not 'string' the value will be casted to the type of column
//--- getting value
void Get(int i,int j,long &recipient) {if(!check_type(i,TYPE_LONG)) {_CHECK0_} _FIRST_.Get(_PARAM1_);};// getting value of i-th row and j-th column
void Get(int i,int j,double &recipient) {if(!check_type(i,TYPE_DOUBLE)) {_CHECK0_} _FIRST_.Get(_PARAM1_);};// getting value of i-th row and j-th column
void Get(int i,int j,datetime &recipient) {if(!check_type(i,TYPE_DATETIME)){_CHECK0_} _FIRST_.Get(_PARAM1_);};// getting value of i-th row and j-th column
void Get(int i,int j,string &recipient) {if(!check_type(i,TYPE_STRING)) {_CHECK0_} _FIRST_.Get(_PARAM1_);};// getting value of i-th row and j-th column
string sGet(int i,int j){return(_FIRST_.get(array_index.Ind(j)));};// returning value of i-th row and j-th column
//--- quick search of position an element in the array
int QuickSearch(int i,long element,int beg,int end,bool mode=false) {if(!check_type(i,TYPE_LONG)){_CHECK_} return(_FIRST_.QuickSearch(_PARAM2_));};
//--- Searches for the first element that is equal to a pattern in a sorted array
int SearchFirst(int i,long element,int beg,int end,bool mode=false) {if(!check_type(i,TYPE_LONG)){_CHECK_} return(_FIRST_.SearchFirst(_PARAM2_));};
//--- Searches for the last element that is equal to a pattern in a sorted array
int SearchLast(int i,long element,int beg,int end,bool mode=false) {if(!check_type(i,TYPE_LONG)){_CHECK_} return(_FIRST_.SearchLast(_PARAM2_));};
//--- Searches for the closest element that is greater than a pattern in a sorted array
int SearchGreat(int i,long element,int beg,int end,bool mode=false) {if(!check_type(i,TYPE_LONG)){_CHECK_} return(_FIRST_.SearchGreat(_PARAM2_));};
//--- Searches for the closest element that is less than a pattern in a sorted array
int SearchLess(int i,long element,int beg,int end,bool mode=false) {if(!check_type(i,TYPE_LONG)){_CHECK_} return(_FIRST_.SearchLess(_PARAM2_));};
//--- Overriding to the types double,datetime,string
int QuickSearch(int i,double element,int beg,int end,bool mode=false) {if(!check_type(i,TYPE_DOUBLE)){_CHECK_} return(_FIRST_.QuickSearch(_PARAM2_));};
int SearchFirst(int i,double element,int beg,int end,bool mode=false) {if(!check_type(i,TYPE_DOUBLE)){_CHECK_} return(_FIRST_.SearchFirst(_PARAM2_));};
int SearchLast (int i,double element,int beg,int end,bool mode=false) {if(!check_type(i,TYPE_DOUBLE)){_CHECK_} return(_FIRST_.SearchLast (_PARAM2_));};
int SearchGreat(int i,double element,int beg,int end,bool mode=false) {if(!check_type(i,TYPE_DOUBLE)){_CHECK_} return(_FIRST_.SearchGreat(_PARAM2_));};
int SearchLess (int i,double element,int beg,int end,bool mode=false) {if(!check_type(i,TYPE_DOUBLE)){_CHECK_} return(_FIRST_.SearchLess (_PARAM2_));};
int QuickSearch(int i,datetime element,int beg,int end,bool mode=false) {if(!check_type(i,TYPE_DATETIME)){_CHECK_} return(_FIRST_.QuickSearch(_PARAM2_));};
int SearchFirst(int i,datetime element,int beg,int end,bool mode=false) {if(!check_type(i,TYPE_DATETIME)){_CHECK_} return(_FIRST_.SearchFirst(_PARAM2_));};
int SearchLast (int i,datetime element,int beg,int end,bool mode=false) {if(!check_type(i,TYPE_DATETIME)){_CHECK_} return(_FIRST_.SearchLast (_PARAM2_));};
int SearchGreat(int i,datetime element,int beg,int end,bool mode=false) {if(!check_type(i,TYPE_DATETIME)){_CHECK_} return(_FIRST_.SearchGreat(_PARAM2_));};
int SearchLess (int i,datetime element,int beg,int end,bool mode=false) {if(!check_type(i,TYPE_DATETIME)){_CHECK_} return(_FIRST_.SearchLess (_PARAM2_));};
int QuickSearch(int i,string element,int beg,int end,bool mode=false) {if(!check_type(i,TYPE_STRING)){_CHECK_} return(_FIRST_.QuickSearch(_PARAM2_));};
int SearchFirst(int i,string element,int beg,int end,bool mode=false) {if(!check_type(i,TYPE_STRING)){_CHECK_} return(_FIRST_.SearchFirst(_PARAM2_));};
int SearchLast (int i,string element,int beg,int end,bool mode=false) {if(!check_type(i,TYPE_STRING)){_CHECK_} return(_FIRST_.SearchLast (_PARAM2_));};
int SearchGreat(int i,string element,int beg,int end,bool mode=false) {if(!check_type(i,TYPE_STRING)){_CHECK_} return(_FIRST_.SearchGreat(_PARAM2_));};
int SearchLess (int i,string element,int beg,int end,bool mode=false) {if(!check_type(i,TYPE_STRING)){_CHECK_} return(_FIRST_.SearchLess (_PARAM2_));};
//--- sorting the second dimension by a selected column, beg - start point, end - end point,
//--- mode - direction of sorting (mode=true means values increase together with indexes)
void SortTwoDimArray(int i,int beg,int end,bool mode=false){_FIRST_.Sort(array_index,beg,end,mode);};
};
//+------------------------------------------------------------------+
//| Destructor of the CTable class |
//+------------------------------------------------------------------+
CTable::~CTable(void)
{
for(int i=0;i=0)first_size=count;
else first_size=start_first_size;
};
//+------------------------------------------------------------------+
//| creation of object of children |
//+------------------------------------------------------------------+
void CTable::SwitchType(int i)
{
ENUM_DATATYPE temp=type_table[i];
switch(type_table[i])
{
case TYPE_DATETIME: first_data[i]=new CDATETIMEArray(); break;
case TYPE_LONG: first_data[i]=new CLONGArray(); break;
case TYPE_DOUBLE: first_data[i]=new CDOUBLEArray(); break;
case TYPE_STRING: first_data[i]=new CSTRINGArray(); break;
default:Print("ERROR case "+__FUNCTION__);break;
};
}
//+------------------------------------------------------------------+
//| changing memory allocated for the two-dimensional array |
//+------------------------------------------------------------------+
void CTable::SecondResize(int j)
{
array_index.ResizeIndexes(j);
for(int i=0;i=first_size)return(false);
if(sor1<0||sor1>=first_size)return(false);
int temp=aic[sor0]; aic[sor0]=aic[sor1]; aic[sor1]=temp;
temp=sor0; sor0=sor1; sor1=temp;
return(true);
};
//+------------------------------------------------------------------+
//| inserting a column in a specified position with pulling |
//| of the other columns |
//+------------------------------------------------------------------+
bool CTable::Insert(int rec,int sor)
{
if(rec<0 || rec>=first_size)return(false);
if(sor<0 || sor>=first_size)return(false);
int temp;
if(recrec;i--)
aic[i]=aic[i-1];
aic[rec]=temp;
}
else
{
temp=aic[sor];
for(int i=sor;i