# Three most basic sorts (insert, bubble, select)

Source: Internet
Author: User
Tags sorts

The insertion is stable, the bubbling stability depends on whether there is an equal sign, and the selection is unstable

`#include <iostream> #include <algorithm> #include <vector> #include <string.h> #include <    Ctype.h> #include <math.h>using namespace std;void fun (), int main () {fun (); return 0;} void Fun () {int temp,i,j,arr1[8]={19,1,23,17,19,55,84,15},arr2[8]={19,1,23,17,19,55,84,15},arr3[8]={ 19,1,23,17,19,55,84,15};//Insert sort for (i=1;i<8;i++) {if (Arr1[i-1]>arr1[i]) {temp=arr1[i];for (j=i-1;temp<arr1 [J]&&j>-1;--j) arr1[j+1]=arr1[j];arr1[j+1]=temp;}} Bubble sort for (int. flag=1,i=1;i<8&&flag;++i) {for (flag=0,j=0;j<8-i;++j) {if (arr2[j]>arr2[j+1]) {flag=1 ; temp=arr2[j+1];arr2[j+1]=arr2[j];arr2[j]=temp;}}} Select sort for (int flag,i=0;i<8-1;i++) {flag=i;for (j=i+1;j<8;j++) if (Arr3[j]<arr3[flag]) flag=j;if (I!=flag) { Temp=arr3[i];arr3[i]=arr3[flag];arr3[flag]=temp;}} for (i=0;i<8;i++) cout<<arr1[i]<< ""; Cout<<endl;for (i=0;i<8;i++) cout<<arr2[i]< < ""; Cout<<endl;for (i=0;i<8;i++) cout<<arr3[i]<< ""; Cout<<endl;}`

The result is shown

Three most basic sorts (insert, bubble, select)

Related Keywords:

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.