ostream& operator<<(ostream& out, Tree * tree) { if(!tree->root->hasChildren()) { out<<tree->root; return out; } out<<tree->root; if(tree->root->left ) { Tree leftsub(tree->root->left); out<<"["<<&leftsub<<"]"; } if(tree->root->right ) { Tree rightsub(tree->root->right); out<<"{"<<&rightsub<<"}"; } return out; }
int main( ) { char s1[ ] = "Hello" ; char s2[ ] = "Hello World" ; char s3[ ] = "Four hundred thirty two" ; char ch, *s ; int i ; system ( "cls" ) ; printf ( "String s1: %s\n", s1 ) ; /* check for the first occurrence of a character */ printf ( "Enter character to search: " ) ; scanf ( "%c", &ch ) ; i = search ( s1, ch ) ; if ( i != -1 ) printf ( "The first occurrence of character %c is found at index no. %d\n\n", ch, i ) ; else printf ( "Character %c is not present in the list.\n", ch ) ; printf ( "String s2: %s\n", s2 ) ; /* compares two strings s1 and s2 */ i = isequals ( s1, s2 ) ; if ( i == 1 ) printf ( "Strings s1 and s2 are identical\n" ) ; else printf ( "Strings s1 and s2 are not identical\n" ) ; i = issmaller ( s1, s2 ) ; if ( i == 1 ) printf ( "String s1 is smaller than string s2\n" ) ; else printf ( "String s1 is not smaller than string s2\n" ) ; i = isgreater ( s1, s2 ) ; if ( i == 1 ) printf ( "String s1 is greater than string s2\n" ) ; else printf ( "String s1 is not greater than string s2\n\n" ) ; /* extract characters at given position */ printf ( "String s3: %s\n", s3 ) ; s = getsub ( s3, 5, 7 ) ; printf ( "Sub string: %s\n", s ) ; free ( s ) ; /* extract leftmost n characters */ s = leftsub ( s3, 4 ) ; printf ( "Left sub string: %s\n", s ) ; free ( s ) ; /* extract rightmost n characters */ s = rightsub ( s3, 3 ) ; printf ( "Right sub string: %s\n", s ) ; free ( s ) ; /* convert string to uppercase */ upper ( s3 ) ; printf ( "String in upper case: %s\n", s3 ) ; /* convert string to lowercase */ lower ( s3 ) ; printf ( "String in lower case: %s\n", s3 ) ; /* reverse the given string */ reverse ( s3 ) ; printf ( "Reversed string: %s\n", s3 ) ; /* replace first occurrence of one char with new one */ replace ( s1, 'H' , 'M' ) ; printf ( "String s1: %s\n", s1 ) ; /* sets a char at a given position */ i = setat ( s1, 'M', 3 ) ; if ( i ) printf ( "String s1: %s\n", s1 ) ; else printf ( "Invalid position.\n" ) ; return 0 ; }