fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. void bubbleSort(char x[10][20],int n){
  4. for(int i=1;i<n;i++)
  5. for(int j=n-1;j>=i;j--)
  6. if(strcmp(x[j],x[j-1])<0){
  7. char tmp[20];
  8. strcpy(tmp,x[j]);
  9. strcpy(x[j],x[j-1]);
  10. strcpy(x[j-1],tmp);
  11. }
  12. }
  13. void show(char x[10][20],int n){
  14. for(int i=0;i<n;i++){
  15. cout<<x[i]<<"\t";
  16. }
  17. cout<<endl;
  18. }
  19. int main(int argc, char const *argv[])
  20. {
  21. char x[10][20] = {"John", "Wen", "Ozil", "Thor", "Merci", "Adam", "Dany", "Terry", "Henry", "Ronal"};
  22. int n=10;
  23. cout<<"Danh sach tao: "<<endl;
  24. show(x,n);
  25. bubbleSort(x,n);
  26. show(x,n);
  27. return 0;
  28. }
Success #stdin #stdout 0.01s 5288KB
stdin
Standard input is empty
stdout
Danh sach tao: 
John	Wen	Ozil	Thor	Merci	Adam	Dany	Terry	Henry	Ronal	
Adam	Dany	Henry	John	Merci	Ozil	Ronal	Terry	Thor	Wen