+ 4
how the data structures works with java codes?
7 Answers
0
bubble sort is no data structure, it is an algorithm.
Data structures are Vector, Linked List, Deque, Stack and so on while algorithm are ways of solving problems, often with a special Data structure.
Bubble sort works like a bubble, the smallest go to the left because it has less "weight" while the biggest go to the right because it has more "weight". I am not really clear right know but with an example it will be better
[6] 4 2 9 3
4 [6] 2 9 3 : 6 switch with 4 as 6>4
4 2 [6] 9 3 : 6 switch with 2 as 6>2
4 2 6 [9] 3 : 6 do not move, we take 9 as 9>6
4 2 6 3 [9] : 9 switch with 3 as 9>3
Now the last value of the array is the biggest, so we sort all other values using the same method
[4] 2 6 3 | 9
2 [4] 6 3 | 9 : 4 switch with 2 as 4>2
2 4 [6] 3 | 9 : 4 do not move, we take 6 as 6>4
2 4 3 [6] | 9 : 6 switch with 3 as 6>3
Now the last two values are sorted, so we continue with :
[2] 4 3 | 6 9
Try to end it by yourself but it is the exact same logic :)
+ 3
thank you, can u give me a one example?
+ 3
bubble sort
+ 3
Thank you very much đ
0
Same as for other languages :)
0
Of which data structure ?
0
Your welcome :)