Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Fast sorting of arrays in C language (including a detailed explanation of the algorithm)

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Network Security >

Share

Shulou(Shulou.com)06/01 Report--

Taking the array a [0] a [1] a [2] a [3] a [4] a [5] a [6] a [7] a [8] a [9] a [10] 032 39 23 45 36 57 14 27 39 as an example, the first round of the implementation mechanism of the core code is explained: first enter quickSort (a, 0,10) Key=0,i=0,j=10, enter the outer while, enter the first inner while, because 0 is the smallest in the array, so j sweeps all the way to the end of the array, jpend0Magi arr [0] = arr [0] = 0; obviously cannot enter the second inner while, because i=j=0 ends the outer while, execute a [0] = key=0; obviously does not enter the first if, enter the second if, execute quickSort (a, 1, 10) Sort from a [1] to a [10], and the first round ends. In the second round, execute quickSort (a, 1, 10), key=2,i=1,j=10, enter the outer while, enter the first inner while, because 2 is the smallest in the incoming segment, so j sweeps all the way to the head, Jaim1dagarr [1] = arr [1] = 2; obviously can not enter the second inner while, because i=j=1 ends the outer while, execute a [1] = key=2; obviously does not enter the first if, enter the second if, execute quickSort (a, 2, 10) Sort from a [2] to a [10], and the second round ends. The third round: execute quickSort (a, 2, 10), key=32,i=2,j=10, enter the outer while, enter the first inner layer while,a [10] = 39 > key=32,--j,j becomes 9 tera [9] = 27

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Network Security

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report