![rad rad]()
我的代码有问题,请提供一些帮助吗?完整代码:#include <iostream>using namespace std;int a[100],k;struct nod { int info; nod *st,*dr; } *rad,*p;void adaug(nod *&rad, int x){ if(!rad) { nod *p = new nod; p -> info = x; p -> st = 0; p -> dr = 0; rad = p; } else if(x < rad -> info) adaug(rad->st,x); else adaug(rad->dr,x);}void SRD(nod *rad,int &k){ if(rad) { SRD(rad -> st,k); a[k] = rad -> info; k++; SRD(rad -> dr,k); }}int main(){ nod *rad = NULL; int n,x,i; cout << "n="; cin >> n; for(i = 1; i <= n; i++) { cin >> x; adaug(rad,x); }SRD(rad,k);while (a[k]){ cout << a[k] << " "; k++; }cout << endl << k; return 0;}SRD是左,根,右交叉,并且adaugare是插入功能。因此,如果我使用cout info 我认为问题出在SRD功能中,所以有什么需要帮助吗?(当它应在像这样的二叉树中打印2 3 4 6 7 8时,它仅打印7: 6(根) 3 8 2 4 7 9 (adsbygoogle = window.adsbygoogle || []).push({}); 最佳答案 像这样...for(i = 0; i < k; i++) cout<<a[i]<<" ";或者像这样i=0;while(i<k){ cout<<a[i]<<" "; i++;}您的代码中的问题是 while(a[k]) (adsbygoogle = window.adsbygoogle || []).push({}); 10-08 08:40