Data structure------C + + pointer bubble sorting algorithm

Source: Internet
Author: User

C + + uses pointers to implement a bubble sort algorithm for an array.

Bubble sort



Bubble sort (Bubble sort) is a simpler sort algorithm in the field of computer science.



Code:
1 /*2 Name: Bubble sort Algorithm3 Copyright:null4 Author: Small x5 date:06-10-14 10:346 description:c++ Bubble ordering of one-dimensional arrays via pointers7 */8 9#include <iostream>Ten  One /*Run this program using the console Pauser or add your own getch, System ("pause") or input loop*/ A#include <stdio.h> -#include <stdlib.h> -  the /*Run this program using the console Pauser or add your own getch, System ("pause") or input loop*/ - voidSortintBintlen) - { -     inti,j,t; +      for(i=0; i<len-1; i++) -     { +          for(j=0; j<len-1-i;j++) A         { at             if(a[j]>a[j+1]) -             { -t=A[j]; -a[j]=a[j+1]; -a[j+1]=T; -             } in         } -     } to } +  - intMainintargcChar**argv) the  { *     inta[6]={1563,454, About, +,48456,455}; $Sort (A,6);Panax Notoginseng     inti; -      for(i=0;i<6; i++) the     { +printf"number%d is%d\n". II1, A[i]); A     } the     return 0; +}

Operation Result:

Code Explanation:

The array name of a one-dimensional array represents the address of the first element of the array, and we need two parameters when passing parameters, one for the first address and the other for the number of elements in the array.

At least these two parameters are required to determine the one-dimensional array.

end!

Welcome to Exchange, sharing the programmer inspirational story. QQ Group of Happy programmers:

Data structure------C + + pointer bubble sorting algorithm

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.