Lists. (C)
//Beloshenko + 2007
//Розмірності полів.
externconstint NVAXDataPoint=100;
externconstint NOfChars=100;
//ВАХ.
class VAXData
{
public:
VAXData();
//private:
int N;
float I[::NVAXDataPoint];
float DeltaI[::NVAXDataPoint];
float U[::NVAXDataPoint];
};
//Конструктор для пустого ВАХу.
VAXData::VAXData()
{
//Зануляємо масив для подальшої роботи.
int i=0;
for(i=0; i<::NVAXDataPoint+1; i++)
{
I[i]=0;
DeltaI[i]=0;
U[i]=0;
};
N=0;
};
//Клас - поле списку.
class CField
{
public:
CField();
int Number;
CField* Next;
//private:
char Name[::NOfChars];
VAXData VAX;
};
//Конструктор класу.
CField::CField()
{
int i=0;
for(i=0; i<::NOfChars+1; i++)
Name[i]=' ';
};
//Список.
CField* List;
//Ініціація списку.
BD_Init_List()
{
List= new CField();
List->Number=0;
};
//Вставка елементу з певним порядковим номером.
BD_Insert_Element()
{
CField* p;
p=List;
if (p->Number==0)
{
//Для нульового елементу.
p->Number=1;
p->Next= new CField();
p->Next->Number=0;
} else
{
//Для інших.
while(p->Number!=0)
{
p->Number=p->Number+1;
p=p->Next;
};
p->Number=1;
p->Next= new CField();
p->Next->Number=0;
};
};
//Заповнення заданого поля списку,
//а саме:
//1. Запис імені;
//2. Запис ВАХ.
char BD_Fill_Element_Name[::NOfChars];
VAXData BD_Fill_Element_VAX;
bool BD_Fill_Element_FillCorrect;
BD_Fill_Element(int el_num)
{
CField* p;
int i;
p=List;
if (p->Number<el_num)
{
BD_Fill_Element_FillCorrect=false;
}
else
{
BD_Fill_Element_FillCorrect=true;
if (p->Number!=el_num)
{
p=p->Next;
};
p->VAX.N=BD_Fill_Element_VAX.N;
for(i=0; i<::NVAXDataPoint; i++)
{
p->VAX.U[i]=BD_Fill_Element_VAX.U[i];
p->VAX.I[i]=BD_Fill_Element_VAX.I[i];
p->VAX.DeltaI[i]=BD_Fill_Element_VAX.DeltaI[i];
};
for(i=0; i<::NOfChars; i++)
{
p->Name[i]=BD_Fill_Element_Name[i];
};
};
};
//Пошук елементу серед списку.
char BD_Find_Element_Name[::NOfChars];
bool BD_Find_Element_FindCorrect;
int BD_Find_Element()
{
CField* p;
int i;
int j;
bool b;
char ch;
p=List;
if (p->Number==0)
{
BD_Find_Element_FindCorrect=false;
}
else
{
BD_Find_Element_FindCorrect=true;
j=0;
loop:
b=true;
j=p->Number;
if(j==0)
goto endloop_dont_find;
j=1;
ch='>';
while(p->Name[j]!=ch)
j++;
for(i=0; i<j; i++)
if(p->Name[i]!=BD_Find_Element_Name[i])
b=false;
if(b)
{
goto endloop_find;
}
else
{
p=p->Next;
};
goto loop;
endloop_find:
j=p->Number;
i=j;
BD_Find_Element_FindCorrect=true;
goto endloop;
endloop_dont_find:
j=p->Number;
i=j;
BD_Find_Element_FindCorrect=false;
goto endloop;
endloop:
i=i; //Пуста команда.
};
return i;
};
//Видалення елементу зі списку.
char BD_Delete_Element_Name[::NOfChars];
bool BD_Delete_Correct;
BD_Delete_Element()
{
CField* p;
int i;
int j=0;
p=List;
for(j=0; j<NOfChars; j++)
BD_Find_Element_Name[j]=BD_Delete_Element_Name[j];
i=BD_Find_Element();
BD_Delete_Correct=BD_Find_Element_FindCorrect;
if(BD_Find_Element_FindCorrect)
{
goto yes_find;
}
else
{
goto dont_find;
};
yes_find:
loop:
if(i==p->Number)
goto endloop;
p=p->Next;
goto loop;
endloop:
loop1:
if(p->Number==0)
goto endloop1;
p->Number=p->Next->Number;
for(j=0; j<NOfChars; j++)
p->Name[j]=p->Next->Name[j];
p->VAX.N=p->Next->VAX.N;
for(j=0; j<NVAXDataPoint; j++)
{
p->VAX.I[j]=p->Next->VAX.I[j];
p->VAX.U[j]=p->Next->VAX.U[j];
p->VAX.DeltaI[j]=p->Next->VAX.DeltaI[j];
};
p=p->Next;
goto loop1;
endloop1:
p->Next=0;
goto endproc;
dont_find:
BD_Delete_Correct=false;
goto endproc;
endproc:
i=i; //Пуста команда.
};
//Взяття потрібного елементу.
char BD_Get_Element_Name[::NOfChars];
bool BD_Get_Element_GetCorrect;
CField* BD_Get_Element_Element; BD_Get_Element()
{
CField* p;
int i;
int j;
bool b;
char ch;
p=List;
if (p->Number==0)
{
BD_Get_Element_GetCorrect=false;
}
else
{
BD_Get_Element_GetCorrect=true;
j=0;
loop:
b=true;
j=p->Number;
if(j==0)
goto endloop_dont_find;
j=1;
ch='>';
while(p->Name[j]!=ch)
j++;
for(i=0; i<j; i++)
if(p->Name[i]!=BD_Get_Element_Name[i])
b=false;
if(b)
{
BD_Get_Element_Element=p;
goto endloop_find;
}
else
{
p=p->Next;
};
goto loop;
endloop_find:
j=p->Number;
i=j;
BD_Get_Element_GetCorrect=true;
goto endloop;
endloop_dont_find:
j=p->Number;
i=j;
BD_Get_Element_GetCorrect=false;
goto endloop;
endloop:
i=i; //Пуста команда.
};
};
