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)