Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 30 additions & 11 deletions C++/remove_special_characters_from_aaray.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
// Name: Shoaib Sabir
// Username: Shoaib019
// Approach:
// Approach: remove_character shifts array to let by one character
// is_special_character checks whether character is special or not
// remove_special_charactes reduce size if last character is special
// and runs loop whenever special character finds in the array it removes
// find special character using is_special_character method and remove
// special charactes using remove_character method
class Solution {
public:
int remove_character(char arr [], char ch, int size){
int remove_character(char arr [], char ch, int size){
int i;
for(i=0; i< size; i++)
{
Expand All @@ -12,7 +17,7 @@ class Solution {
}
if(i < size)
{
size -= 1;
size--;
for(int j=i; j < size; j++)
{
arr[j] = arr[j + 1];
Expand All @@ -22,12 +27,26 @@ class Solution {
return size;
}

void remove_special_charactes(char arr [],int size) {

for(int i=0; i< size; i++)
{
if(arr[i] < 97 && arr[i] < 122)
size = remove_character(arr,arr[i],size);
}
}
bool is_special_character(char ch){
if((!(ch >= 97 && ch <= 122) && !(ch >= 65 && ch <= 90) ))
return true;
else
return false;
}

int remove_special_charactes(char arr [],int size) {
if(is_special_character(arr[size - 1]))
{
size--;
}
for(int i=0; i< size; i++)
{
if(is_special_character(arr[i]))
{
size = remove_character(arr,arr[i],size);
i--;
}
}
return size;
}
};