GOOGOLCheng / algorithm

0 stars 0 forks source link

Write a C language code to solve the following problem: For the data sequence {8,9,10,4,5,6,20,1,2}, use bubble sort (in descending order from back to front, with ascending order required) and at least how many passes are required? #1

Open GOOGOLCheng opened 1 year ago

GOOGOLCheng commented 1 year ago

A C language code to implement the bubble sort algorithm. Then, by actually running this algorithm, we can obtain the minimum number of passes required to sort a given data sequence. a9397b0b0f3d4924ec643ff801fa09b

image image

GOOGOLCheng commented 1 year ago

chatgpt3.5‘s answer is wrong: image

GOOGOLCheng commented 1 year ago

c in clion: image output: image

GOOGOLCheng commented 1 year ago

In the code provided by chatgpt3.5, the bubble starts from the beginning of the array, and larger elements move faster to the back of the array. In this case, the minimum number of passes is 8. If the bubble starts from the end of the array, smaller elements will move faster to the front of it. In this case, the minimum number of passes is 6.