Обьясните как работает метод пузырька | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Обьясните как работает метод пузырька

for(int i = 0; i < count - 1; i++){ for(int j = 0; j < count - 1; j++){ if(mas[j+1] > mas[j]){ int swap = mas[j]; mas[j] = mas[j+1]; mas[j+1] = swap; } } } P.s. count - кол-во елементов в динамическом массиве mas. 3 вопроса 1)Что собой будут представлять переменные i и j в цикле. А точнее, что они будут делать? 2) Почему им присвоено значение 0? 3)Почему условие пока они < count - 1?

11th Oct 2019, 1:14 PM
Egor
Egor - avatar
1 Answer
+ 5
1. i and j are use to call the array 2. it started with zero because 0 is the first index of the array 3. It is count-1 because the last index of the array array length minus 1. Just like when you have 9 elements in the array, the last index will be 8
29th Oct 2019, 7:46 AM
MCGAmedCoder gamerArtist
MCGAmedCoder gamerArtist - avatar