public static void reverse_in_place(String[] array)
时间: 2024-06-06 14:07:24 浏览: 10
{
int i = 0;
int j = array.length - 1;
while (i < j) {
String temp = array[i];
array[i] = array[j];
array[j] = temp;
i++;
j--;
}
}
相关问题
reverse_string
Sure! To reverse a string, you can simply iterate through the characters of the string in reverse order and append them to a new string. Here's an example in Python:
```python
def reverse_string(string):
reversed_string = ""
for i in range(len(string) - 1, -1, -1):
reversed_string += string[i]
return reversed_string
# Example usage
string = "Hello, World!"
reversed_string = reverse_string(string)
print(reversed_string)
```
The output will be "!dlroW ,olleH".
用c语言写一段代码,函数名为void reverse_chars_in_place;形式参数为char *cs, Uint len;In the space of s, reverse the character sequence. I.e. abc becomes cba. nothing is returned.
```
void reverse_chars_in_place(char *cs, Uint len) {
Uint i;
char tmp;
for (i = 0; i < len / 2; ++i) {
tmp = cs[i];
cs[i] = cs[len - i - 1];
cs[len - i - 1] = tmp;
}
}
```
注意:在这段代码中,我假设 Uint 类型已经被定义为无符号整型。
相关推荐
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)