
- •Пояснительная записка
- •Задание на курсовую работу
- •Содержание
- •Введение
- •Постановка задачи
- •1.1 Цель и задачи работы
- •1.2 Обоснование выбора средства программирования
- •1.3 Входная и выходная информация
- •1.4 Требования к аппаратному обеспечению
- •1.5 Требования к программному обеспечению
- •2 Сведения из теории
- •3 Алгоритм решения задачи
- •5. Руководство пользователя
- •Заключение
- •Список литературы:
- •Приложение 1
Приложение 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();
}
//---------------------------------------------------------------------------