Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Пояснительная записка1.docx
Скачиваний:
10
Добавлен:
04.05.2019
Размер:
151.95 Кб
Скачать

Приложение 1

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

#include <vcl.h>

#pragma hdrstop

#include "Unit1.h"

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

#pragma package(smart_init)

#pragma resource "*.dfm"

TForm1 *Form1;

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

__fastcall TForm1::TForm1(TComponent* Owner)

: TForm(Owner)

{

}

class Node

{

public:

int number;

Node* last;

Node* next;

};

Node* head = NULL;

Node* tail = NULL;

Node* ptrLast = NULL;

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

void __fastcall TForm1::Button1Click(TObject *Sender)

{

int numb = Edit1->Text.ToInt();

Node* ptr = new Node;

ptr->number = numb;

ptr->next = NULL;

tail = ptr;

Edit1->Text="";

if (head == NULL){

head = ptr;

ptrLast = ptr;

ptr->last = NULL;

}

else{

ptr->last = ptrLast;

ptrLast->next = ptr;

ptrLast = ptr;

}

}

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

void __fastcall TForm1::Button2Click(TObject *Sender)

{

Node* ptr = NULL;

if (head == NULL)

{

Label2->Caption = "Очередь пуста";

}

else{

ptr = tail;

Label2->Caption = "";

while (1)

{

Label2->Caption = Label2->Caption+ptr->number+" ";

//cout<<ptr->number<<" ";

if (ptr->last == 0)

break;

ptr = ptr->last;

}

//cout<<"\n\n";

}

}

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

void __fastcall TForm1::Button3Click(TObject *Sender)

{

Node* ptrDelete = NULL;

if (head == NULL)

{

Label2->Caption = "Очередь пуста";

}

else{

if (head->next == NULL)

{

head = NULL;

tail = NULL;

delete tail;

}

else

{

ptrDelete = head;

head = ptrDelete->next;

head->last = NULL;

delete ptrDelete;

}

}

}

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

void __fastcall TForm1::Button4Click(TObject *Sender)

{

Node* ptr = NULL;

int key = Edit2->Text.ToInt();;

if (head == NULL)

{

Label2->Caption = "Очередь пуста";

}

ptr = head;

while (1)

{

if (key == ptr->number)

{

Label3->Caption="Элемент найден";

break;

}

if (ptr->next == NULL)

{

Label3->Caption="Элемент не найден";

break;

}

ptr = ptr->next;

}

}

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

void __fastcall TForm1::Edit2Click(TObject *Sender)

{

Edit2->Text="";

}

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

void __fastcall TForm1::Edit1Click(TObject *Sender)

{

Edit1->Text="";

}

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

void __fastcall TForm1::Button5Click(TObject *Sender)

{

Form1->Close();

}

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

26