Description
Enter three strings, which are output in order from small to large. Two sort functions are implemented using pointers and references, respectively. Enter and output data in the main function.
Input
3 Line string
Output is 3 rows from small to large. implemented by pointers. Output to 3 lines from small to large. Implemented by the reference method. Sample Input
Cdeafgabc
Sample Output
Abcafgcdeabcafgcde
Code
#include <iostream> #include <cstring>using namespace std;void sort1 (char *s1,char *s2,char *s3) {char t[100 ]; if (strcmp (S1,S2) >0) {strcpy (T,S1); strcpy (S1,S2); strcpy (s2,t); } if (strcmp (S2,S3) >0) {strcpy (T,S3); strcpy (S3,S2); strcpy (s2,t); } if (strcmp (S1,S2) >0) {strcpy (T,S1); strcpy (S1,S2); strcpy (s2,t); }}void sort2 (String &s1,string &s2,string &s3) {string T; if (S1>S2) {t=s1; S1=S2; s2=t; } if (S2>S3) {t=s3; S3=S2; s2=t; } if (S1>S2) {t=s1; S1=S2; s2=t; }}int Main () {void Sort1 (char *,char *,char *); void Sort2 (String &,string &,string &); Char s1[100],s2[100],s3[100]; Char *p1,*p2,*p3; String R1,r2,r3; cin>>s1>>s2>>s3; R1=string (S1); r2=string (S2); R3=string (S3); P1=S1; P2=S2; P3=S3; SorT1 (P1,P2,P3); cout<<s1<<endl<<s2<<endl<<s3<<endl; Sort2 (R1,R2,R3); cout<<r1<<endl<<r2<<endl<<r3<<endl; return 0;}
Some items-enter three strings, output in order from small to large