data structure program

you have a string like sachin ramesh tendulkar and the given character by user is 'a'.then the expected output will be schin rmesh tendulkraaa-note that all the three occurrence of the character 'a' are removed from their original position and dumped at last..


you have the complexity of O(n) and only O(1) amount of extra memory is created.No extra array can be used.you have to be modified in-place



PLZ if anyone can help i am thankful
Go through the string an remove all of the 'a' characters while keeping a count. Then append that many 'a' characters to the end.
i am able to make it by two loops bt not by one and if i use count variable then it count occurrence of 'a' but not it's position if u can make then plzz...
#include <stdio.h>
02

03
/* see 'fix' to remove ALL char's ... */
04
void removeChar( char cStr[], char let );
05

06
int main()
07
{
08
char myString[] = "Cats are black! Oh,... not always,... some are white also!";
09
printf( "Unmodified string: %s\n\n", myString );
10
removeChar( myString, '.' );
11
printf( "Modified string: %s\n", myString );
12

13
printf( "\nPress 'Enter' to continue ... " );
14
getchar();
15
return 0;
16
}
17

18
void removeChar( char cStr[], char let )
19
{
20
unsigned i, j; /* need to declare at top for 'C' compile ... */
21

22
for( i = j = 0; cStr[i] != 0; ++i )
23
if( cStr[i] == let ) continue;
24
else cStr[j++] = cStr[i] ;
25

26
cStr[j] = 0; /* Now ... null terminate */
27
}
Topic archived. No new replies allowed.