字符串逆序(遞歸非遞歸實現)

#include<iostream.h>
#include<string.h>
void fun(const char *src)
{
 const char *p=src;
 while(*p++!='/0')
  ;
 p--;
 while(p-->src)
  cout<<*p<<endl;
 

}
void fun2(char *p)
{
 if(*p)
 {
 int i=0;
 i=strlen(p)-1;

 p=p+1;

 fun2(p);
 }
 cout<<*p;
}
void main()
{
 
 char p[] ="ABCDEFGHI";  
    fun(p); 
 cout<<p+1<<endl;
 fun2(p);

 
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章