串存储结构定义如下,编程实现将r中字符按照相反次序存放在r中。
时间: 2024-03-18 18:40:42 浏览: 11
假设该串的存储结构为:
```
typedef struct {
char data[MAXSIZE];
int length;
} SqString;
```
其中 `MAXSIZE` 是串的最大长度。
那么按照相反次序存放字符的算法如下:
```c
void reverse(SqString *r) {
char temp;
int i, j;
for (i = 0, j = r->length - 1; i < j; i++, j--) {
temp = r->data[i];
r->data[i] = r->data[j];
r->data[j] = temp;
}
}
```
该算法通过交换从前往后和从后往前遍历的字符来实现将字符按照相反次序存放。
相关推荐
![application/msword](https://img-home.csdnimg.cn/images/20210720083327.png)
![7z](https://img-home.csdnimg.cn/images/20210720083312.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![7z](https://img-home.csdnimg.cn/images/20210720083312.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![7z](https://img-home.csdnimg.cn/images/20210720083312.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![7z](https://img-home.csdnimg.cn/images/20210720083312.png)
![7z](https://img-home.csdnimg.cn/images/20210720083312.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![7z](https://img-home.csdnimg.cn/images/20210720083312.png)