阅读:2473回复:0
[求助]怎么做?
<P ><FONT face="Times New Roman">1. </FONT>说出算法输出的结果</P>
<P > <FONT face="Times New Roman">void main( )<p></p></FONT></P> <P ><FONT face="Times New Roman">{<p></p></FONT></P> <P ><FONT face="Times New Roman">Stack S;<p></p></FONT></P> <P ><FONT face="Times New Roman">Char x,y;<p></p></FONT></P> <P ><FONT face="Times New Roman">InitStack(S);<p></p></FONT></P> <P ><FONT face="Times New Roman">X=’a’;y=’b’;<p></p></FONT></P> <P ><FONT face="Times New Roman">Push(S,x); Push(S,’c’); Push(S,y);<p></p></FONT></P> <P ><FONT face="Times New Roman">Pop(S,x); Push(S,’e’); Push(S,x);<p></p></FONT></P> <P ><FONT face="Times New Roman">Pop(S,x); Push(S,’q’);<p></p></FONT></P> <P ><FONT face="Times New Roman">while(!StackEmpty(S)){ Pop(S,y);printf(“%c ”,y); };<p></p></FONT></P> <P ><FONT face="Times New Roman">printf(“%c\n”,x);<p></p></FONT></P> <P ><FONT face="Times New Roman">}</FONT></P> <P ><FONT face="Times New Roman"></FONT> </P><FONT face="Times New Roman"><p> <P >1. 说出下列算法的功能。<B > </B></P> <P >int depth(BTreeNode * root) <p></p></P> <P >{<p></p></P> <P >int d, p; <p></p></P> <P >p=0;<p></p></P> <P >if(root==NULL) return(p); <p></p></P> <P >else{ <p></p></P> <P >d=depth(root->left);<p></p></P> <P >if(d>p) p=d; <p></p></P> <P >d=depth(root->right);<p></p></P> <P >if(d>p)p=d;<p></p></P> <P >}<p></p></P> <P >p=p+1;<p></p></P> <P >return(p);<p></p></P> <P >}<p></p></P> <P ></p></FONT> </P> |
|
|