//string reversal using stack
//#include <iostream>
//#include <stdlib.h>
#include <stdio.h>
#include <stack>
#include <cstring>
using namespace std;
void Reverse(char *C,int n)
{
stack <char> S;
//loop for push
for (int i = 0; i<n; i++)
{
S.push(C[i]);
}
//loop for pop
for (int j = 0; j<n; j++)
{
C[j] = S.top();//overwrite the character at index i
S.pop();
}
}
int main()
{
char C[51];
printf ("Enter a string : ");
gets(C);
Reverse(C,strlen(C));
printf ("Output = %s",C);
printf ("\n");
}这几个警告是怎么回事?大神们帮我解析一下啊。。。。。还有就是代码是不是有问题,Reverse的两个for循环并列关系,应该是同步执行吧,如果是同步执行,那么第二个for循环就错了呀。。。。我感觉有点蒙
- 3 回答
- 0 关注
- 2565 浏览
添加回答
举报
0/150
提交
取消