Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma once
- #include <stdlib.h>
- namespace Queue_new {
- using namespace System;
- using namespace System::ComponentModel;
- using namespace System::Collections;
- using namespace System::Windows::Forms;
- using namespace System::Data;
- using namespace System::Drawing;
- struct Double_List
- {
- int Data;
- Double_List *Next, *Prior;
- };
- struct Ochered
- {
- Double_List *Begin;
- Double_List *End;
- };
- /// <summary>
- /// Summary for Form1
- ///
- /// WARNING: If you change the name of this class, you will need to change the
- /// 'Resource File Name' property for the managed resource compiler tool
- /// associated with all .resx files this class depends on. Otherwise,
- /// the designers will not be able to interact properly with localized
- /// resources associated with this form.
- /// </summary>
- public ref class Form1 : public System::Windows::Forms::Form
- {
- public:
- Form1(void)
- {
- InitializeComponent();
- //
- //TODO: Add the constructor code here
- //
- }
- protected:
- /// <summary>
- /// Clean up any resources being used.
- /// </summary>
- ~Form1()
- {
- if (components)
- {
- delete components;
- }
- }
- private: System::Windows::Forms::Label^ label2;
- protected:
- private: System::Windows::Forms::Label^ label1;
- private: System::Windows::Forms::Button^ button2;
- private: System::Windows::Forms::TextBox^ textBox3;
- private: System::Windows::Forms::TextBox^ textBox2;
- private: System::Windows::Forms::TextBox^ textBox1;
- private: System::Windows::Forms::Button^ button1;
- private:
- /// <summary>
- /// Required designer variable.
- /// </summary>
- System::ComponentModel::Container ^components;
- #pragma region Windows Form Designer generated code
- /// <summary>
- /// Required method for Designer support - do not modify
- /// the contents of this method with the code editor.
- /// </summary>
- void InitializeComponent(void)
- {
- this->label2 = (gcnew System::Windows::Forms::Label());
- this->label1 = (gcnew System::Windows::Forms::Label());
- this->button2 = (gcnew System::Windows::Forms::Button());
- this->textBox3 = (gcnew System::Windows::Forms::TextBox());
- this->textBox2 = (gcnew System::Windows::Forms::TextBox());
- this->textBox1 = (gcnew System::Windows::Forms::TextBox());
- this->button1 = (gcnew System::Windows::Forms::Button());
- this->SuspendLayout();
- //
- // label2
- //
- this->label2->AutoSize = true;
- this->label2->Font = (gcnew System::Drawing::Font(L"Segoe Print", 14.25F, System::Drawing::FontStyle::Bold, System::Drawing::GraphicsUnit::Point,
- static_cast<System::Byte>(204)));
- this->label2->Location = System::Drawing::Point(28, 96);
- this->label2->Name = L"label2";
- this->label2->Size = System::Drawing::Size(375, 33);
- this->label2->TabIndex = 13;
- this->label2->Text = L"Количество обрабатываемых цифр";
- //
- // label1
- //
- this->label1->AutoSize = true;
- this->label1->Font = (gcnew System::Drawing::Font(L"Segoe Script", 18, System::Drawing::FontStyle::Bold, System::Drawing::GraphicsUnit::Point,
- static_cast<System::Byte>(0)));
- this->label1->Location = System::Drawing::Point(109, 22);
- this->label1->Name = L"label1";
- this->label1->Size = System::Drawing::Size(581, 40);
- this->label1->TabIndex = 12;
- this->label1->Text = L"Удаление из очереди элементов кратные 3";
- this->label1->Click += gcnew System::EventHandler(this, &Form1::label1_Click);
- //
- // button2
- //
- this->button2->Font = (gcnew System::Drawing::Font(L"Segoe Print", 14.25F, System::Drawing::FontStyle::Bold, System::Drawing::GraphicsUnit::Point,
- static_cast<System::Byte>(204)));
- this->button2->Location = System::Drawing::Point(223, 209);
- this->button2->Name = L"button2";
- this->button2->Size = System::Drawing::Size(180, 48);
- this->button2->TabIndex = 11;
- this->button2->Text = L"Обработать";
- this->button2->UseVisualStyleBackColor = true;
- this->button2->Click += gcnew System::EventHandler(this, &Form1::button2_Click);
- //
- // textBox3
- //
- this->textBox3->Font = (gcnew System::Drawing::Font(L"Segoe Print", 14.25F, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
- static_cast<System::Byte>(204)));
- this->textBox3->Location = System::Drawing::Point(420, 214);
- this->textBox3->Name = L"textBox3";
- this->textBox3->Size = System::Drawing::Size(277, 41);
- this->textBox3->TabIndex = 10;
- //
- // textBox2
- //
- this->textBox2->Font = (gcnew System::Drawing::Font(L"Segoe Print", 14.25F, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
- static_cast<System::Byte>(204)));
- this->textBox2->Location = System::Drawing::Point(420, 93);
- this->textBox2->Name = L"textBox2";
- this->textBox2->Size = System::Drawing::Size(79, 41);
- this->textBox2->TabIndex = 9;
- //
- // textBox1
- //
- this->textBox1->Font = (gcnew System::Drawing::Font(L"Segoe Print", 14.25F, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
- static_cast<System::Byte>(204)));
- this->textBox1->Location = System::Drawing::Point(420, 149);
- this->textBox1->Name = L"textBox1";
- this->textBox1->Size = System::Drawing::Size(277, 41);
- this->textBox1->TabIndex = 8;
- //
- // button1
- //
- this->button1->Font = (gcnew System::Drawing::Font(L"Segoe Print", 14.25F, System::Drawing::FontStyle::Bold, System::Drawing::GraphicsUnit::Point,
- static_cast<System::Byte>(204)));
- this->button1->Location = System::Drawing::Point(223, 142);
- this->button1->Name = L"button1";
- this->button1->Size = System::Drawing::Size(180, 48);
- this->button1->TabIndex = 7;
- this->button1->Text = L"Сгенерировать";
- this->button1->UseVisualStyleBackColor = true;
- this->button1->Click += gcnew System::EventHandler(this, &Form1::button1_Click);
- //
- // Form1
- //
- this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
- this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
- this->ClientSize = System::Drawing::Size(756, 293);
- this->Controls->Add(this->label2);
- this->Controls->Add(this->label1);
- this->Controls->Add(this->button2);
- this->Controls->Add(this->textBox3);
- this->Controls->Add(this->textBox2);
- this->Controls->Add(this->textBox1);
- this->Controls->Add(this->button1);
- this->Name = L"Form1";
- this->Text = L"Лабораторная работа 5. Выполнила Моисеенко Валерия К12-2";
- this->ResumeLayout(false);
- this->PerformLayout();
- }
- #pragma endregion
- void Make_Double_List(int n, Double_List** Head, Double_List* Prior)
- {
- if(n > 0)
- {
- (*Head) = new Double_List();
- (*Head)->Data = rand()%100+0;
- (*Head)->Prior = Prior;
- (*Head)->Next = NULL;
- Make_Double_List(n - 1, &((*Head)->Next), (*Head));
- }
- else
- (*Head) = NULL;
- }
- String^ Print_Double_List(Double_List* Head)
- {
- String^ result = "";
- if(Head != NULL)
- result += (Convert::ToString(Head->Data) + " " + Print_Double_List(Head->Next));
- else
- result = " ";
- return result;
- }
- Double_List* Insert_Item_Double_List(Double_List* Head, int Number, int DataItem)
- {
- Double_List *NewItem = new Double_List;
- NewItem->Data = DataItem;
- NewItem->Prior = NULL;
- NewItem->Next = NULL;
- if(Head == NULL)
- {
- Head = NewItem;
- }
- else
- {
- Double_List *Current = Head;
- for(int i = 1; i < Number && Current->Next != NULL; i++)
- Current = Current->Next;
- if(Number == 0)
- {
- NewItem->Next = Head;
- Head->Prior = NewItem;
- Head = NewItem;
- }
- else
- {
- if(Current->Next != NULL)
- Current->Next->Prior = NewItem;
- NewItem->Next = Current->Next;
- Current->Next = NewItem;
- NewItem->Prior = Current;
- Current = NewItem;
- }
- }
- return Head;
- }
- Double_List* Delete_Item_Double_List(Double_List* Head, int Number)
- {
- Double_List *ptr;
- Double_List *Current = Head;
- for(int i = 1; i < Number && Current != NULL; i++)
- Current = Current->Next;
- if(Current != NULL)
- {
- if(Current->Prior == NULL)
- {
- Head = Head->Next;
- delete(Current);
- Head->Prior = NULL;
- }
- else
- {
- if(Current->Next == NULL)
- {
- Current->Prior->Next = NULL;
- delete(Current);
- Current = Head;
- }
- else
- {
- ptr = Current->Next;
- Current->Prior->Next = Current->Next;
- Current->Next->Prior = Current->Prior;
- delete(Current);
- Current = ptr;
- }
- }
- }
- return Head;
- }
- bool Find_Item_Double_List(Double_List* Head, int DataItem)
- {
- Double_List *ptr;
- ptr = Head;
- while(ptr != NULL)
- {
- if(DataItem == ptr->Data)
- return true;
- else
- ptr = ptr->Next;
- }
- return false;
- }
- bool Empty_Double_List(Double_List* Head)
- {
- if(Head != NULL)
- return false;
- else
- return true;
- }
- void Delete_Double_List(Double_List* Head)
- {
- if(Head != NULL)
- {
- Delete_Double_List(Head->Next);
- delete Head;
- }
- }
- void Make_Queue(int n, Ochered* End_Queue)
- {
- Make_Double_List(n, &(End_Queue->Begin), NULL);
- Double_List *ptr;
- ptr = End_Queue->Begin;
- while(ptr->Next != NULL)
- ptr = ptr->Next;
- End_Queue->End = ptr;
- }
- String^ Print_Queue(Ochered* Begin_Queue)
- {
- return Print_Double_List(Begin_Queue->Begin);
- }
- void Add_Item_Queue(int NewElem, Ochered* End_Queue)
- {
- if(End_Queue->Begin == NULL)
- {
- End_Queue->Begin = new Double_List();
- End_Queue->Begin->Data = NewElem;
- End_Queue->Begin->Prior = NULL;
- End_Queue->Begin->Next = NULL;
- End_Queue->End = End_Queue->Begin;
- return;
- }
- End_Queue->End = Insert_Item_Double_List(End_Queue->End, 1, NewElem)->Next;
- }
- bool Empty_Queue(Ochered* Begin_Queue)
- {
- return Empty_Double_List(Begin_Queue->Begin);
- }
- void Clear_Queue(Ochered* Begin_Queue)
- {
- return Delete_Double_List(Begin_Queue->Begin);
- }
- int Extract_Item_Queue(Ochered* Begin_Queue)
- {
- int NewElem;
- if(Begin_Queue->Begin->Next != NULL)
- {
- NewElem = Begin_Queue->Begin->Data;
- Begin_Queue->Begin = Delete_Item_Double_List(Begin_Queue->Begin, 1);
- }
- else
- {
- NewElem = Begin_Queue->Begin->Data;
- Begin_Queue->Begin = NULL;
- }
- return NewElem;
- }
- bool krat3(int el)
- {
- for(int i = 2; i < el; i++)
- if(el%3==0)
- return false;
- return true;
- }
- private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
- int A, k;
- textBox1->Text = "";
- textBox3->Text = "";
- if(textBox2->Text == "")
- k = 10;
- else
- k = Convert::ToInt32(textBox2->Text);
- for(int i = 0; i < k; i++)
- {
- A = rand()%100+0;
- textBox1->Text += (A + " ");
- }
- }
- private: System::Void button2_Click(System::Object^ sender, System::EventArgs^ e) {
- textBox3->Text = "";
- String ^ first_string, ^ chislo;
- Ochered *My_Queue = new Ochered();
- first_string = textBox1->Text;
- int i = 0;
- while(i < first_string->Length)
- {
- chislo = "";
- while(first_string[i] != ' ')
- {
- chislo += first_string[i];
- i++;
- if(i >= first_string->Length)
- break;
- }
- Add_Item_Queue(Convert::ToInt32(chislo), My_Queue);
- if(i >= first_string->Length)
- break;
- while(first_string[i] == ' ')
- {
- i++;
- if(i >= first_string->Length)
- break;
- }
- }
- int buf;
- while(My_Queue->Begin != NULL)
- {
- buf = Extract_Item_Queue(My_Queue);
- if(krat3(buf))
- textBox3->Text += (buf + " ");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement