C language for Bubble sorting and Bubble Sorting

Source: Internet
Author: User

C language for Bubble sorting and Bubble Sorting

C language for Bubble Sorting

Algorithm Implementation:

# Include
 
  
# Include
  
   
Int main () {int arr [2] [3]; int I, j, k, temp; int * p = arr; printf ("\ n ======================== array initialization =========================\ n "); for (I = 0; I <2*3; I ++) {printf ("input element: \ n"); scanf ("% d ", p + I );} printf ("\ n ============================ start sort =====================\ n "); for (I = 0; I <2*3-1; I ++) {for (j = 0; j <(2*3-1)-I; j ++) {if (* (p + j)> * (p + j + 1) {temp = * (p + j + 1 ); * (p + j + 1) = * (p + j); * (p + j) = temp ;}} printf ("\ n ====================== % d times out ==================== ==\ n ", I + 1); for (k = 0; k <2*3; k ++) {printf ("% d", * (p + k ));}} printf ("\ n ================================================= \ n "); for (I = 0; I <2*3; I ++) {printf ("arr: % d \ n", * (p + I ));} return 0 ;}
  
 
The running result is as follows:


Bubble sort Demo:

Algorithm analysis:

Sorting Method

Worst Time Analysis Average time complexity Stability Space complexity
Bubble Sorting O (n2) O (n2) Stability O (1)

Related Article

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.