//---------------------------------------------------------------------------


#pragma hdrstop
#include <vcl.h>
#include "Unit2.h"
#include "Unit1.h"

//---------------------------------------------------------------------------

#pragma package(smart_init)
Queue::Queue(int n)
{
 len=0;
 maxlen=n;
 v=new float [maxlen];
}
void Queue::AddElem(float El)
{
 v[len]=El;
 len++;
}
void Queue::DelElem()
{
 if (len!=0)
 {
  for (int i=0;i<len-1;i++)
   v[i]=v[i+1];
  len--;
 }
 else
  ShowMessage("Очередь пуста");
}
int Queue::dx(int j)
{
 return (8+Form1->Canvas->TextWidth(v[j])+8);
}

int Queue::dy(int j)
{
 return (8+Form1->Canvas->TextHeight(v[j])+8);
} 
void Queue::OutQueue()
{
 int i,max=0;
 Form1->Canvas->FillRect(TRect(0,0,Form1->Width,Form1->Height));
 for (i=1;i<len;i++)
 if (v[i]>v[max]) max=i;
 for (i=0;i<len;i++)
 {
  Form1->Canvas->Rectangle(30+(dx(max)+30)*i,Form1->Height-100,30+dx(max)+(30+dx(max))*i,Form1->Height-100+dy(max));
  Form1->Canvas->TextOutA(30+(dx(max)+30)*i+(dx(max))/2-(dx(i)-16)/2,Form1->Height-100+(dy(max))/2-(dy(i)-16)/2,v[i]);
  if (i!=len-1)
  {
   Form1->Canvas->MoveTo(30+dx(max)+(30+dx(max))*i,Form1->Height-100+dy(max)/2);
   Form1->Canvas->LineTo(30+dx(max)+(30+dx(max))*i+5,Form1->Height-100+dy(max)/2-5);
   Form1->Canvas->MoveTo(30+dx(max)+(30+dx(max))*i+5,Form1->Height-100+dy(max)/2+5);
   Form1->Canvas->LineTo(30+dx(max)+(30+dx(max))*i,Form1->Height-100+dy(max)/2);
   Form1->Canvas->LineTo(30+dx(max)+(30+dx(max))*i+30,Form1->Height-100+dy(max)/2);

  }
 }
  for (i=0;i<15;i++)
  Form1->StringGrid1->Cells[i][0]="";
 for (i=0;i<len;i++)
  Form1->StringGrid1->Cells[i][0]=v[i];
}