******************************************************************************************
Reverse the given character string in place without any duplication of characters
******************************************************************************************
Source Code :
===========
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 | program : To reverse the given character string in place without any duplication of characters #include<iostream.h> #include<conio.h> #include<string.h> char temp[30]; int check(char x,int n) { for(int i=0;i<n;i++) { if(temp[i]==x) return 0; } return 1; } void reverse(char str[],int n) { int count=0,i,j,l=0; for(i=0,j=0;i<n;i++) { count=check(str[i],i); if(count==1) { temp[j]=str[i]; j++; l++; } } cout<<"\nThe reversed character string is: "; for(i=l;i>=0;i--) cout<<temp[i]; } void main() { char str[30],ch; int n=0; clrscr(); cout<<"Enter any string and end with $: "; cin.get(ch); do { str[n]=ch; n++; cin.get(ch); }while(ch!='$'); str[n]=''; reverse(str,n); getch(); } /* Output: Enter any string and end with $: football$ The reversed character string is: labtof |
26 total views, 3 views today