Reverse an array without affecting special characters | GeeksforGeeks

preview_player
Показать описание

This video is contributed by Harshit Jain.
Рекомендации по теме
Комментарии
Автор

Solution is little wrong. Assume you have more than one special char together.

Instead of if(!alpha....) It should be while(! Alpha).

prabinpanda
Автор

Can you provide solution in JAVASCRIPT programming

venuboini
Автор

I wrote the same on C# but my mentor told me solve the task with Stack )

I-PixALbI-I
Автор

Sir could you please help with Coding to ignore special characters whlie printing the even and odd characters in a string

govindtiwari
Автор

Can you provide solution in C programming

logenaldo
Автор

class Solution
{
public:

bool isAlphabet(char x)
{
return ( (x >= 'A' && x <= 'Z') ||
(x >= 'a' && x <= 'z') );
}

string reverse(string str)
{
// Initialize left and right pointers
int r = str.size() - 1, l = 0;

// Traverse string from both ends until
// 'l' and 'r'
while (l < r)
{
// Ignore special characters
if (!isAlphabet(str[l]))
l++;
else if(!isAlphabet(str[r]))
r--;

else // Both str[l] and str[r] are not spacial
{
swap(str[l], str[r]);
l++;
r--;
}
}
return str;
}
};

wecan