C-language Bubble sort Recursive method

Source: Internet
Author: User

1#include <stdio.h>2#include <stdlib.h>3 intMain ()4 {5     6     voidBubbleint*a,intn);7     8     inti,n,a[ -];9     Tenprintf"Please enter the number of elements in the array (no more than 100):"); Onescanf"%d",&n); A      -      for(;n<1|| N> -;){ -printf"the number of elements is out of range, please reenter:"); thescanf"%d",&N);  -}printf ("\ n"); -      -      for(i=0; i<n;i++){ +printf"Please enter the element a[%d]:", i); -scanf"%d",&a[i]); +}printf ("\ n"); A      atprintf"you have entered the following elements: \ n"); -      for(i=0; i<n;i++){ -printf"%d", A[i]); -}printf ("\ n"); -      - Bubble (a,n); in      -printf"increment arrangement to: \ n"); to      for(i=0; i<n;i++){ +printf"%d", A[i]); -}printf ("\ n"); the      *System"Pause"); $     return 0;Panax Notoginseng } -  the voidBubbleint*a,intN) + { A     inti; the     if(n==1){ +         return; -     } $      for(i=0; i<n-1; i++){ $         if(a[i]>a[i+1]){ -             intt=a[i];a[i]=a[i+1];a[i+1]=T; -         }         the     } -Bubble (a,n-1);Wuyi}
View Code

C-language Bubble sort Recursive method

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.