Mustaqil ish mavzu: Bubble sort algoritmi. Bajardi: Allayarov Tohirjon


Bubble Sort algoritmining kamchiliklari


Download 104.22 Kb.
bet4/4
Sana16.06.2023
Hajmi104.22 Kb.
#1518787
1   2   3   4
Bog'liq
Bubble sort

Bubble Sort algoritmining kamchiliklari

  • Asosiy kamchilik - bu talab qilinadigan vaqt. Bu katta ma'lumotlar to'plamlari uchun juda samarasiz, ish vaqti O(n2).

  • Bundan tashqari, toshbaqalarning mavjudligi turni sezilarli darajada sekinlashtirishi mumkin.


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Bubble_sort


{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void BubbleSort(int[] arr)
{
int n = arr.Length;
for (int i = 0; i < n - 1; i++)
{
for (int j = 0; j < n - i - 1; j++)
{
if (arr[j] > arr[j + 1])
{
int temp = arr[j];
arr[j] = arr[j + 1];
arr[j + 1] = temp;
}
}
}
}
private void btnSort_Click(object sender, EventArgs e)
{
int[] arr = new int[listBox1.Items.Count];
// Ichiga listBoxda kiritilgan sonların miqdoriga teng massiv yaratiladi.
for (int i = 0; i < listBox1.Items.Count; i++)
{
arr[i] = int.Parse(listBox1.Items[i].ToString());
}
BubbleSort(arr);
// Yaratilgan massivni tartiblash uchun Bubble Sort algoritmi chaqiriladi.
listBox1.Items.Clear();
//ListBox elementlari tozalash uchun ishlatiladi.
for (int i = 0; i < arr.Length; i++)
{
listBox1.Items.Add(arr[i]);
//Tartiblangan elementlarni listBoxga qo'shish uchun ishlatiladi.
}
}
}
}

Foydalanilgan adabiyotlar



  • https://dosenit.com/kuliah-it/rpl/algoritma-bubble-sort

  • https://www.geeksforgeeks.org/bubble-sort/

  • https://www.youtube.com/watch?v=LOVEvLck-EM

  • https://www.bbc.co.uk/bitesize/guides/zjdkw6f/revision/4

Download 104.22 Kb.

Do'stlaringiz bilan baham:
1   2   3   4




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling