Bubble sort · bubble sort
Bubble sort
Sort an array into ascending order in place using bubble sort: walk through the array comparing each pair of neighbours and swapping them if they're in the wrong order. After each full pass the largest remaining value has "bubbled" to the end, so repeat until everything is sorted.
บับเบิลซอร์ต
เรียงลำดับอาเรย์เป็นแบบเพิ่มขึ้น in place โดยใช้ bubble sort: เดินผ่านอาเรย์เปรียบเทียบคู่เพื่อนบ้านและสลับหากอยู่ในลำดับที่ผิด หลังการเดินรอบทั้งหมดค่าที่เหลือมากสุดได้ "bubbled" ไปยังส่วนท้ายแล้ว ดังนั้นทำซ้ำจนกว่าทุกอย่างจะเรียงลำดับแล้ว
Complete void bubble_sort(int *a, int n) to sort the n elements into ascending order, in place. Repeatedly pass through the array swapping any out-of-order neighbours. · เติม void bubble_sort(int *a, int n)为了เรียง ⟨n⟩ ตัว element เป็นลำดับเพิ่มขึ้น ในตำแหน่งเดิม ทำซ้ำการผ่าน array โดยสลับเพื่อนบ้านที่ไม่เป็นระเบียบ
Click Run to see the output here. · คลิก Run เพื่อดูผลลัพธ์ที่นี่