Untitled

Anonymous
plain_text
03/16/2026 5:37 PM
12.5 KB
16
Indexable
#pragma once

namespace sortt {

	using namespace System;
	using namespace System::ComponentModel;
	using namespace System::Collections;
	using namespace System::Windows::Forms;
	using namespace System::Data;
	using namespace System::Drawing;

	/// <summary>
	/// Summary for Form1
	/// </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::TextBox^  textBox1;
	protected: 
	private: System::Windows::Forms::TextBox^  textBox3;
	private: System::Windows::Forms::RadioButton^  radioButton1;
	private: System::Windows::Forms::Button^  button1;


	private:
		/// <summary>
		/// Required designer variable.
		/// </summary>
		int* a;
		int n;
	private: System::Windows::Forms::RadioButton^  radioButton2;


			 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>
				bool Comp(int &x, int &y) {
			return x < y;
		}

		void swap(int a[], int i, int lowindex) {
			int temp = a[i];
			a[i] = a[lowindex];
			a[lowindex] = temp;
		}
///////////////////////////////////////////////
				void quicksort(int data[], size_t n) {
			size_t pivot_index;  
			size_t n1;          
			size_t n2;          

			if (n > 1) {
			
				partition(data, n, pivot_index);

			
				n1 = pivot_index;
				n2 = n - n1 - 1;

				quicksort(data, n1);
				quicksort((data + pivot_index + 1), n2);
			}
		}

			
			void partition(int data[], size_t n, size_t& pivot_index) {
				int pivot = data[0];   
				size_t too_big_index = 1;  
				size_t too_small_index = n - 1;  

				while (too_big_index <= too_small_index) {

					while (too_big_index < n && data[too_big_index] <= pivot) {
						too_big_index++;
					}


					while (data[too_small_index] > pivot) {
						too_small_index--;
					}

					if (too_big_index < too_small_index) {
						swap(data, too_big_index, too_small_index);
					}
				}


				pivot_index = too_small_index;
				swap(data, pivot_index, 0);
		}

			//////////////////////////////////////////////
						void heapsort(int data[], size_t n) {
				for (size_t i = n / 2; i > 0; --i) {
					heapify(data, n, i - 1);
				}

				for (size_t i = n - 1; i > 0; --i) {
					swap(data, 0, i);
					heapify(data, i, 0);
				}
			}

			void heapify(int data[], size_t n, size_t i) {
				size_t largest = i;
				size_t left = 2 * i + 1;
				size_t right = 2 * i + 2;

				if (left < n && data[left] > data[largest]) {
					largest = left;
				}
				if (right < n && data[right] > data[largest]) {
					largest = right;
				}

				if (largest != i) {
					swap(data, i, largest);
					heapify(data, n, largest);
				}
			}

		
		void InitializeComponent(void)
		{
			this->textBox1 = (gcnew System::Windows::Forms::TextBox());
			this->textBox3 = (gcnew System::Windows::Forms::TextBox());
			this->radioButton1 = (gcnew System::Windows::Forms::RadioButton());
			this->button1 = (gcnew System::Windows::Forms::Button());
			this->radioButton2 = (gcnew System::Windows::Forms::RadioButton());
			this->SuspendLayout();
			// 
			// textBox1
			// 
			this->textBox1->BorderStyle = System::Windows::Forms::BorderStyle::FixedSingle;
			this->textBox1->Font = (gcnew System::Drawing::Font(L"Segoe UI", 12, System::Drawing::FontStyle::Bold, System::Drawing::GraphicsUnit::Point, 
				static_cast<System::Byte>(0)));
			this->textBox1->ForeColor = System::Drawing::Color::DarkSlateGray;
			this->textBox1->Location = System::Drawing::Point(70, 42);
			this->textBox1->Margin = System::Windows::Forms::Padding(4, 5, 4, 5);
			this->textBox1->Multiline = true;
			this->textBox1->Name = L"textBox1";
			this->textBox1->ScrollBars = System::Windows::Forms::ScrollBars::Vertical;
			this->textBox1->Size = System::Drawing::Size(170, 390);
			this->textBox1->TabIndex = 1;
			this->textBox1->TextChanged += gcnew System::EventHandler(this, &Form1::textBox1_TextChanged);
			// 
			// textBox3
			// 
			this->textBox3->BorderStyle = System::Windows::Forms::BorderStyle::FixedSingle;
			this->textBox3->Font = (gcnew System::Drawing::Font(L"Segoe UI", 12, System::Drawing::FontStyle::Bold, System::Drawing::GraphicsUnit::Point, 
				static_cast<System::Byte>(0)));
			this->textBox3->ForeColor = System::Drawing::Color::DarkSlateGray;
			this->textBox3->Location = System::Drawing::Point(272, 42);
			this->textBox3->Margin = System::Windows::Forms::Padding(4, 5, 4, 5);
			this->textBox3->Multiline = true;
			this->textBox3->Name = L"textBox3";
			this->textBox3->ScrollBars = System::Windows::Forms::ScrollBars::Vertical;
			this->textBox3->Size = System::Drawing::Size(170, 390);
			this->textBox3->TabIndex = 7;
			this->textBox3->TextChanged += gcnew System::EventHandler(this, &Form1::textBox3_TextChanged);
			// 
			// radioButton1
			// 
			this->radioButton1->AutoSize = true;
			this->radioButton1->Location = System::Drawing::Point(478, 244);
			this->radioButton1->Margin = System::Windows::Forms::Padding(4, 5, 4, 5);
			this->radioButton1->Name = L"radioButton1";
			this->radioButton1->Size = System::Drawing::Size(128, 32);
			this->radioButton1->TabIndex = 8;
			this->radioButton1->TabStop = true;
			this->radioButton1->Text = L"quick sort";
			this->radioButton1->UseVisualStyleBackColor = true;
			this->radioButton1->CheckedChanged += gcnew System::EventHandler(this, &Form1::radioButton1_CheckedChanged);
			// 
			// button1
			// 
			this->button1->BackColor = System::Drawing::Color::Red;
			this->button1->FlatStyle = System::Windows::Forms::FlatStyle::Popup;
			this->button1->Font = (gcnew System::Drawing::Font(L"Segoe UI", 12, System::Drawing::FontStyle::Bold, System::Drawing::GraphicsUnit::Point, 
				static_cast<System::Byte>(0)));
			this->button1->Location = System::Drawing::Point(478, 284);
			this->button1->Name = L"button1";
			this->button1->Size = System::Drawing::Size(163, 64);
			this->button1->TabIndex = 9;
			this->button1->Text = L"Sort";
			this->button1->UseVisualStyleBackColor = false;
			this->button1->Click += gcnew System::EventHandler(this, &Form1::button1_Click);
			// 
			// radioButton2
			// 
			this->radioButton2->AutoSize = true;
			this->radioButton2->Location = System::Drawing::Point(478, 202);
			this->radioButton2->Margin = System::Windows::Forms::Padding(4, 5, 4, 5);
			this->radioButton2->Name = L"radioButton2";
			this->radioButton2->Size = System::Drawing::Size(123, 32);
			this->radioButton2->TabIndex = 10;
			this->radioButton2->TabStop = true;
			this->radioButton2->Text = L"heap sort";
			this->radioButton2->UseVisualStyleBackColor = true;
			this->radioButton2->CheckedChanged += gcnew System::EventHandler(this, &Form1::radioButton2_CheckedChanged);
			// 
			// Form1
			// 
			this->AutoScaleDimensions = System::Drawing::SizeF(12, 28);
			this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
			this->BackColor = System::Drawing::Color::FromArgb(static_cast<System::Int32>(static_cast<System::Byte>(44)), static_cast<System::Int32>(static_cast<System::Byte>(62)), 
				static_cast<System::Int32>(static_cast<System::Byte>(80)));
			this->ClientSize = System::Drawing::Size(1041, 728);
			this->Controls->Add(this->radioButton2);
			this->Controls->Add(this->button1);
			this->Controls->Add(this->radioButton1);
			this->Controls->Add(this->textBox3);
			this->Controls->Add(this->textBox1);
			this->Font = (gcnew System::Drawing::Font(L"Segoe UI", 12, System::Drawing::FontStyle::Bold, System::Drawing::GraphicsUnit::Point, 
				static_cast<System::Byte>(0)));
			this->ForeColor = System::Drawing::SystemColors::HighlightText;
			this->Margin = System::Windows::Forms::Padding(4, 5, 4, 5);
			this->Name = L"Form1";
			this->Text = L"Form1";
			this->ResumeLayout(false);
			this->PerformLayout();

		}
#pragma endregion
	private: System::Void radioButton4_CheckedChanged(System::Object^  sender, System::EventArgs^  e) {
			 }
	private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {
				n = textBox1->Lines->Length;
				a = new int[n];
				for (int i = 0; i < n; i++) {
				a[i] = Convert::ToInt32(textBox1->Lines[i]);
			}
				if(radioButton1->Checked){
				quicksort(a,n);
				MessageBox::Show("You Choose QuickSort");
			}
				else if(radioButton1->Checked){
				heapsort(a,n);
				MessageBox::Show("You Choose heap");
				}
				else{
				MessageBox::Show("Please Choose!!");
			}
				textBox3->Text = "";
			for (int i = 0; i < n; i++){
				textBox3->Text = textBox3->Text + Convert::ToString(a[i]) + "\r\n";
			}
			 }
private: System::Void radioButton1_CheckedChanged(System::Object^  sender, System::EventArgs^  e) {
		 }
private: System::Void textBox3_TextChanged(System::Object^  sender, System::EventArgs^  e) {
		 }
private: System::Void textBox1_TextChanged(System::Object^  sender, System::EventArgs^  e) {
		 }
private: System::Void radioButton2_CheckedChanged(System::Object^  sender, System::EventArgs^  e) {
		 }
};
}

///////////
Editor is loading...
Leave a Comment