Hi,
I wanted to write a code that would delete a given character from a string. I have come up with the following snippet.
Now, while this does my work, it is giving me a worst case complexity of O(n^2). Can anyone help me on improving this.
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
void Push(char *, int i);
int n=6;
int main()
{
clrscr();
char *p = "helelo";
char delChar = 'e';
for(int i=0;i<5;i++)
{
if(*(p + i) == delChar)
{
Push(p, i);
}
}
cout<<p<<endl;
getch();
return 1;
}
void Push(char *p, int i)
{
for(int k=i;k<n;k++)
{
*(p + k) = *(p+k+1);
}
}
Thanks