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

How to understand the ordering in the basis of C language

2025-03-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

What this article shares with you is about how to understand the ranking in the basis of C language. The editor thinks it is very practical, so I share it with you. I hope you can get something after reading this article. Let's take a look at it with the editor.

Bubble sort Bubble sort (classic simple sorting algorithm)

How it works: a set of data in which two adjacent numbers are compared and exchanged in the order from small to big or from big to small; the comparison is repeated until there is no longer need to exchange, that is, the set of data is sorted.

Array to be sorted: 6 2 4 3 8 1 7 9 5

According to the principle of Bubble sort:

1. From the start data 6 > > end data 5 as a big cycle

two。 The first big cycle begins: the comparison of adjacent pairs of data is part of this big cycle. If the comparison meets the conditions, it will be exchanged until the last pair of data is compared, and the big cycle ends.

3. Repeat the operation, do the second big cycle from the starting data, and repeat the adjacent data comparison.

The basic way of writing:

# include int main (void) {int iRecitemjret; int Arr [9] = {6, 2, 4, 3, 8, 1, 7, 9, 5); for

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

Development

Wechat

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

12
Report