In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/03 Report--
What is bubble sort algorithm code? I believe that many inexperienced people are helpless about this. For this reason, this article summarizes the causes and solutions of the problem. Through this article, I hope you can solve this problem.
Bubble sorting is a relatively simple sorting algorithm in computer science that repeatedly visits a column of elements to be sorted, compares two adjacent elements in turn, and swaps them if the order (e.g., from large to small, from Z to A) is wrong.
void vBubbleSort(int arr[], int len){ int i, j, temp; for (j = 0; j
< len - 1; j++){ //每次最大元素就像气泡一样"浮"到数组的最后 for (i = 0; i < len - 1 - j; i++){ //依次比较相邻的两个元素,使较大的那个向后移 if(arr[i] >arr[i + 1]){ //swap two numbers temp = arr[i]; arr[i] = arr[i + 1]; arr[i + 1] = temp; } } }}void vBubbleSortChange(int arr[], int len){ int i,j,temp; int swapped = 1; for (j = 0; swapped; j++){ //Each time the largest element "floats" like a bubble to the end of the array swapped = 0; for (i = 0; i
< len - 1 - j; i++){ //依次比较相邻的两个元素,使较大的那个向后移 if(arr[i] >arr[i + 1]){ //swap two numbers temp = arr[i]; arr[i] = arr[i + 1]; arr[i + 1] = temp; swapped = 1; } }// if( Swapped == 0) {j = len-1;}//If there is no element swap, the sequence is sequential, exit the loop }}void vCockTailSort(int arr[],int len){ int tmp,i,left=0,right = len-1; while(left
< right){ for(i=left;iarr[i+1]){ tmp = arr[i]; arr[i] = arr[i+1]; arr[i+1] = tmp; } } right--; for(i=right;i>left;i--){//reverse bubble, determine minimum if(arr[i]left;i--){//reverse bubble, determine minimum if(arr[i]
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.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.