#include <iostream>
#include <algorithm>
#include <stdio.h>
using namespace std;
struct E{
char t,value;
int no;
};
void BubbleSort(E *C,int N){
for (int i=0;i<N;i++){
for (int j=N-1;j>0;j--){
if (C[j].value < C[j-1].value){
std::swap(C[j],C[j-1]);
}
}
}
}
void SelectionSort(E* C,int N){
for(int i=0;i<N;i++){
int minj=i;
for(int j=i;j<N;j++){
if(C[j].value<C[minj].value){
minj=j;
}
}
std::swap(C[i],C[minj]);
}
}
void print(E *C,int N){
bool state=true;
for(int i=0;i<N;i++){
if(i>0)printf(" ");
printf("%c%c",C[i].t,C[i].value);
if(i>0&&C[i-1].value==C[i].value&&C[i-1].no>C[i].no)state=false;
}
printf("\n%s\n",state?"Stable":"Not stable");
}
int main() {
// your code goes here
int N;
scanf("%d\n",&N);
E C[37],C2[37];
for(int i=0;i<N;i++){
char c;
scanf("%c%c%c",&C[i].t,&C[i].value,&c);
C[i].no=i;
C2[i]=C[i];
}
BubbleSort(C,N);
print(C,N);
SelectionSort(C2,N);
print(C2,N);
return 0;
}
最終更新:2016年03月30日 07:14