Комментарии:
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;
}
}
}
}
}
what does it mean j<a.length-i-1 ??? Please helppp
Ответитьtop
ОтветитьWhy do we need the temp variable?
ОтветитьMany thanks!
Ответитьit was perfect.
all of it
U r videos are my go to for all the sorting algos, Thank you for making these, Great help, Keep up the great work!
ОтветитьGreat Video mate!
Ответитьthank you for these perfect video.
Ответитьhey you, thank you
ОтветитьVery easy to understand, but I wish u made those tutorial in C.
ОтветитьtHank you broooo
ОтветитьThe comparison with the two cups was really intuitive! I wish someone had explained me variable swapping with that example.
ОтветитьAhhhh yeah
ОтветитьVery helpful video, thank you!
ОтветитьLegend.
ОтветитьThanks!
ОтветитьI still come back to this video from time to time to rehash my BubbleSort.
Thanks BRO!
👍🏻
Ответить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 ?
Ответитьyikes
ОтветитьThanks from Egypt❤🔥
Ответитьplease can i get slides?
ОтветитьThanks Mate!!
ОтветитьGood explantation, Thanks for sharing
ОтветитьThank you very much bro, you put so much time and effort into your videos!
Ответитьthank you for the video, very easy to understand with your explanation
Ответить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 ❤
ОтветитьThanks
ОтветитьThanks from Italy!
Ответитьthanks for clarify this
Ответитьohhhhhh yyeaahhhhhhhhhhhhhh
Ответитьoooo yeahhh
ОтветитьAs always... excellent videos! Thanks!
ОтветитьI don't understand why everyone uses arrays instead of lists. Working with lists is much much more accessible.
ОтветитьBro can you make data structures and algorithms in python please?
ОтветитьThank you. It was so helpful!!
ОтветитьWhat should I do if I'm dealing with a large data set?
ОтветитьNew bro here loved you video brooooo🤘🤘🤘
Ответитьman you diagram / bubble sort picture speaks a lot. now i understand. thanks bro.
Ответитьi dont understand the "J" loop, why do you substract "i"? could someone explain pls
ОтветитьI love u!!!! Thank u for making the concept so clear n understandable💝
ОтветитьBro is the best when it comes to explaining. I hope this guy blows up all over yt. I will support him
ОтветитьThese videos are great. Really helpful for my studying, thank you
Ответитьwow
Ответитьwhy making the second loop j<array.length -1 -i ?
j < array.length - 1 is also working , please explain
thanku bro
ОтветитьIntroduction for me😂😂😂😂
Ohhh yeah😾🎭🎭🎭🎭
!
Ответитьamazing
Ответить