fork download
  1. #include <iostream>
  2. #include <cstring>
  3.  
  4. using namespace std;
  5.  
  6. int main (){
  7.  
  8. char data[10][40] = {
  9. "",
  10. "Welcome",
  11. " !\"#$%&'()*+,-./0123456789:;<=>?@",
  12. "aBCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`",
  13. "abcdefghijklmnopqrstuvwxyZ{||||||||||}",
  14. "CD_ROM",
  15. "ROM",
  16. "SCS",
  17. "3.5 Floppi",
  18. ""
  19. };
  20.  
  21.  
  22. cout<<"Printing the array as is"<<endl<<endl;
  23.  
  24. for (int i=0; i<10; i++){
  25. cout<<data[i]<<endl;
  26. }
  27.  
  28. cout<<endl<<"Ordering the data in Alphabetical order"<<endl<<endl;
  29.  
  30.  
  31. // bubble sort
  32.  
  33. for (int i=0 ; i<10-1 ; ++i) {
  34. char Tcopy[40];
  35. for (int j=i+1 ; j<10 ; ++j) {
  36. if (strcmp(data[i], data[j]) > 0) {
  37. strcpy(Tcopy, data[i]);
  38. strcpy(data[i], data[j]);
  39. strcpy(data[j], Tcopy);
  40. }
  41. }
  42. }
  43.  
  44.  
  45. cout<<"Printing the array Sorted"<<endl<<endl;
  46.  
  47. for (int i=0; i<10; i++){
  48. cout<<data[i]<<endl;
  49. }
  50.  
  51.  
  52. // Pause
  53. cout<<endl<<endl<<endl<<"Please Close Console Window"<<endl;
  54. cin.ignore('\n', 1024);
  55. return(0);
  56. }
Success #stdin #stdout 0.01s 2688KB
stdin
Standard input is empty
stdout
Printing the array as is


Welcome
 !"#$%&'()*+,-./0123456789:;<=>?@
aBCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`
abcdefghijklmnopqrstuvwxyZ{||||||||||}
CD_ROM
ROM
SCS
3.5 Floppi


Ordering the data in Alphabetical order

Printing the array Sorted



 !"#$%&'()*+,-./0123456789:;<=>?@
3.5 Floppi
CD_ROM
ROM
SCS
Welcome
aBCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`
abcdefghijklmnopqrstuvwxyZ{||||||||||}



Please Close Console Window