C-language bubbling query tutorial

Source: Internet
Author: User

Bubble Query Tutorial

#include <stdio.h>intMain () {Doublearr[]={9,6,1,7,8,3,0,4,5,2};inti,j;printf ("\n************ before queuing *************\n"); for(i=0;i<Ten; i++){if(I! =9) printf ("%d,", Arr[i]);Elseprintf ("%d", Arr[i]);} for(i=8; i>=0; i--)//control the maximum subscript for each trip comparison{ for(j=0; j<=i;j++)//control subscript for each adjacent element comparison{if(arr[j]>arr[j+1])//When the previous number is larger than the number that follows{DoubleTemp//define temporary Variable tempTEMP=ARR[J];//Assign the previous number to temparr[j]=arr[j+1];//reverse position of the number of front and reararr[j+1]=temp;//put the larger number in the back}}}printf ("\n************ sort of *************\n"); for(i=0;i<Ten; i++){if(I! =9) printf ("%d,", Arr[i]);Elseprintf ("%d", Arr[i]);}return 0; }

Output results

9 6 1 7 8 3 0,452// pre-sort output 012 3 4 5 6 7 8 9 // output results after sorting

This is I read the C tutorial after the simulation write a piece of programming, I hope to help you!

C-language bubbling query tutorial

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.