01/10/2018, 14:21

Nhờ xem giúp code đã đúng theo yêu cầu hay chưa

After the first pass, the largest number is guaranteed to be in the highest-numbered element
of the array; after the second pass, the two highest numbers are “in place,” and
so on. Instead of making nine comparisons on every pass, modify the bubble sort to
make eight comparisons on the second pass, seven on the third pass and so on.

Cho hỏi làm vậy có đúng yêu cầu chưa các bác??

rogp10 viết 16:25 ngày 01/10/2018

Sửa một chữ SIZE (kích cỡ đúng) thành size (kích cỡ chưa sắp xếp) là ngon. [spoiler]Tất nhiên là nên dùng insertion cho mảng nhỏ vì nó nhanh & logic cũng dễ theo dõi.[/spoiler]

Hung viết 16:29 ngày 01/10/2018

Đúng hay không thì bác phải viết test case kiểm tra.

Jacaré Junior viết 16:36 ngày 01/10/2018

Tui thử rồi, nếu bỏ --size thì mảng sẽ so sánh 9 cặp , không thì sẽ giảm 1 cặp mỗi lần swap, tui hỏi thử xem cho chắc ăn.

Bài liên quan
0