C program to swap adjacent characters of a String
Given a string str, the task is to swap adjacent characters of this string in C. Examples:
Input: str = "geeks" Output: NA Not possible as the string length is odd Input: str = "geek" Output: egke
- Check if the length of the string is even or odd.
- If the length is odd, swapping cannot be done.
- If the length is even, take each character of the string one by one and swap it with the adjacent character.
Below is the implementation of the above approach:
Time complexity: O(length(str))
Auxiliary space: O(1)