剛剛寫了#536用了遞洄,一開始也是用了全域變數,可是就是不想用全域變數,
後來想一想,用pointer就可以解決了,可是有個語法我實在搞不清楚了...
請看一下註解的地方
#include <iostream>
using std::cout;
using std::cin;
using std::endl;
void post_order(char *s,char **middle)
{
char temp;
char *a=s;
if (*s!='\0')
{
while (*a!=(**middle))
a++;
temp=*a,*a='\0',(*middle)++;
post_order(s,middle);
post_order(a+1,middle);
cout<<temp;
}
}
main()
{
char preorder[27];
char inorder[27];
char *temp;
while (cin>>preorder>>inorder)
{
temp=preorder;
post_order(inorder,&temp);//這個地方居然不能用
cout<<endl; //post_order(inorder,&preorder);
} //why?我記得preorder就是地存放位
return 0; //位置不是,用個temp去裝不也沒改變
} //什麼??十分移惑
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 218.161.12.54
※ 編輯: kc655039 來自: 218.161.12.54 (02/20 02:24)