fork download
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main (){
  6.  
  7. char heroes[11][17] = { "Captain America", "Thor", "Wolverine", "Cyclops", "Goliath", "Beast", "Angel", "Colossus", "Hulk", "Quicksilver", "Ironman"};
  8.  
  9. cout<<"Printing the array as is"<<endl<<endl;
  10.  
  11. for (int i=0; i<12; i++){
  12. cout<<heroes[i]<<endl;
  13. }
  14.  
  15. cout<<endl<<"Ordering the heroes in Alphabetical order"<<endl<<endl;
  16.  
  17.  
  18.  
  19. char temp = NULL;
  20. // bubble sort
  21. for(int i=0;i<11;i++){
  22. for(int j=0; j<(11-1); j++){
  23. if (heroes[i][0] < heroes[j][0]){
  24. for (int k=0; k<17-1; k++){
  25. swap(heroes[i][k], heroes[j][k]);
  26. }
  27.  
  28. }
  29. }
  30. }
  31.  
  32. cout<<"Printing the array Sorted"<<endl<<endl;
  33.  
  34. for (int i=0; i<12; i++){
  35. cout<<heroes[i]<<endl;
  36. }
  37.  
  38.  
  39. // Pause
  40. cout<<endl<<endl<<endl<<"Please Close Console Window"<<endl;
  41. cin.ignore('\n', 1024);
  42. return(0);
  43. }
Success #stdin #stdout 0.02s 2732KB
stdin
Standard input is empty
stdout
Printing the array as is

Captain America
Thor
Wolverine
Cyclops
Goliath
Beast
Angel
Colossus
Hulk
Quicksilver
Ironman
�˿�/[�P���˿%�H�P���˿%�H�

Ordering the heroes in Alphabetical order

Printing the array Sorted

Angel
Beast
Captain America
Cyclops
Colossus
Goliath
Hulk
Ironman
Quicksilver
Thor
Wolverine
�˿�/[�P���˿%�H�P���˿%�H�



Please Close Console Window