Learn Bubble Sort in 7 minutes

Learn Bubble Sort in 7 minutes

Bro Code

3 года назад

218,707 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

Bro Code
Bro Code - 24.05.2021 18:13

public class Main{

// bubble sort = pairs of adjacent elements are compared, and the elements
// swapped if they are not in order.

// Quadratic time O(n^2)
// small data set = okay-ish
// large data set = BAD (plz don't)

public static void main(String[] args) {

int array[] = {9, 1, 8, 2, 7, 3, 6, 4, 5};

bubbleSort(array);

for(int i : array) {
System.out.print(i);
}
}

public static void bubbleSort(int array[]) {

for(int i = 0; i < array.length - 1; i++) {
for(int j = 0; j < array.length - i - 1; j++) {
if(array[j] > array[j+1]) {
int temp = array[j];
array[j] = array[j+1];
array[j+1] = temp;
}
}
}
}
}

Ответить
Norma S
Norma S - 27.09.2023 00:41

what does it mean j<a.length-i-1 ??? Please helppp

Ответить
João Tavares
João Tavares - 24.09.2023 17:04

top

Ответить
Julian Robinson
Julian Robinson - 11.09.2023 22:55

Why do we need the temp variable?

Ответить
Jack Lagos
Jack Lagos - 09.09.2023 19:06

Many thanks!

Ответить
bit
bit - 09.09.2023 06:49

it was perfect.
all of it

Ответить
ASHMIKA Nln
ASHMIKA Nln - 01.09.2023 10:40

U r videos are my go to for all the sorting algos, Thank you for making these, Great help, Keep up the great work!

Ответить
Stefanos Fragoulis
Stefanos Fragoulis - 30.08.2023 00:45

Great Video mate!

Ответить
AnnanasMangoPapaya
AnnanasMangoPapaya - 21.08.2023 16:26

thank you for these perfect video.

Ответить
Arabboy Ismoilov
Arabboy Ismoilov - 09.08.2023 19:10

hey you, thank you

Ответить
Geografix
Geografix - 06.08.2023 00:22

Very easy to understand, but I wish u made those tutorial in C.

Ответить
Genesis Cereno
Genesis Cereno - 21.07.2023 19:53

tHank you broooo

Ответить
DHoneyBeeKingdom
DHoneyBeeKingdom - 18.07.2023 13:05

The comparison with the two cups was really intuitive! I wish someone had explained me variable swapping with that example.

Ответить
Z E E S H A N
Z E E S H A N - 11.07.2023 21:26

Ahhhh yeah

Ответить
Plankalkül Compiler
Plankalkül Compiler - 02.07.2023 19:41

Very helpful video, thank you!

Ответить
Jacob
Jacob - 02.07.2023 08:42

Legend.

Ответить
Mr. Loser
Mr. Loser - 17.06.2023 18:43

Thanks!

Ответить
Barely Coding
Barely Coding - 14.06.2023 20:45

I still come back to this video from time to time to rehash my BubbleSort.

Thanks BRO!

Ответить
Bekzat Tursynbay
Bekzat Tursynbay - 13.06.2023 20:02

👍🏻

Ответить
CodeAmmar
CodeAmmar - 12.06.2023 16:00

thx man for the amazing video , I wanted to note that since the inner loop has 8 elements to be compared and the last element won't get compared because the second element then will already be sorted, so for that the outerloop should be array.length - 2 right ?

Ответить
Chandupatla Praman
Chandupatla Praman - 05.06.2023 22:57

yikes

Ответить
Ahmed Refat Mohamed
Ahmed Refat Mohamed - 31.05.2023 10:51

Thanks from Egypt❤‍🔥

Ответить
Ahmed Refat Mohamed
Ahmed Refat Mohamed - 31.05.2023 10:49

please can i get slides?

Ответить
Youcef Mantas
Youcef Mantas - 26.05.2023 18:34

Thanks Mate!!

Ответить
Dharmesh Ajudiya
Dharmesh Ajudiya - 23.05.2023 10:01

Good explantation, Thanks for sharing

Ответить
DankMemeQueen
DankMemeQueen - 14.05.2023 17:37

Thank you very much bro, you put so much time and effort into your videos!

Ответить
jun
jun - 14.05.2023 08:36

thank you for the video, very easy to understand with your explanation

Ответить
Aaron Fernando
Aaron Fernando - 01.05.2023 17:17

Ey Brooooo ... i love you man ... not even my uni lecturer explained sorting this well .. saw this video 1 day prior to my exam and it helped meee soo much.. really appriciate BROOO ..Much Love from Sri Lanka ❤

Ответить
Файзулла Асатуллаев
Файзулла Асатуллаев - 20.04.2023 06:59

Thanks

Ответить
Jerryyy
Jerryyy - 15.04.2023 19:01

Thanks from Italy!

Ответить
محمد & mohammed
محمد & mohammed - 07.04.2023 15:51

thanks for clarify this

Ответить
vishu
vishu - 06.04.2023 20:54

ohhhhhh yyeaahhhhhhhhhhhhhh

Ответить
deniz
deniz - 06.04.2023 15:10

oooo yeahhh

Ответить
Ale Acevedo
Ale Acevedo - 28.03.2023 07:30

As always... excellent videos! Thanks!

Ответить
Ádám Jurácsik
Ádám Jurácsik - 17.03.2023 16:41

I don't understand why everyone uses arrays instead of lists. Working with lists is much much more accessible.

Ответить
Short-Shots
Short-Shots - 14.03.2023 14:44

Bro can you make data structures and algorithms in python please?

Ответить
Şahin Yusifli
Şahin Yusifli - 13.03.2023 17:59

Thank you. It was so helpful!!

Ответить
Chefs Kiss
Chefs Kiss - 10.03.2023 19:57

What should I do if I'm dealing with a large data set?

Ответить
learner
learner - 01.03.2023 18:24

New bro here loved you video brooooo🤘🤘🤘

Ответить
Prasad Vasupalli
Prasad Vasupalli - 28.02.2023 14:55

man you diagram / bubble sort picture speaks a lot. now i understand. thanks bro.

Ответить
Joel Pose
Joel Pose - 17.02.2023 23:33

i dont understand the "J" loop, why do you substract "i"? could someone explain pls

Ответить
AliiiCc Yee
AliiiCc Yee - 14.01.2023 17:47

I love u!!!! Thank u for making the concept so clear n understandable💝

Ответить
GamingPro1000
GamingPro1000 - 28.12.2022 06:36

Bro is the best when it comes to explaining. I hope this guy blows up all over yt. I will support him

Ответить
Zippo1234
Zippo1234 - 22.11.2022 01:54

These videos are great. Really helpful for my studying, thank you

Ответить
Tiba koo
Tiba koo - 21.11.2022 21:46

wow

Ответить
Maro 993
Maro 993 - 30.10.2022 09:46

why making the second loop j<array.length -1 -i ?
j < array.length - 1 is also working , please explain

Ответить
e/acc
e/acc - 26.10.2022 21:27

thanku bro

Ответить
collyne city
collyne city - 19.10.2022 06:36

Introduction for me😂😂😂😂
Ohhh yeah😾🎭🎭🎭🎭

Ответить
Youssof Programmer
Youssof Programmer - 05.10.2022 18:53

!

Ответить
Youssof Programmer
Youssof Programmer - 05.10.2022 18:53

amazing

Ответить