(
PP[=(NT2B(k!|3 [ 本 资 料 来 源 于 贵 州 学 习 网 考研一方考研专业课 http://Www.gzU521.com ] (
PP[=(NT2B(k!|3
六.下面一段程序输出什么?
void main(void)
{ stack s; queue q; pqueue pq; char ch;
char sentence[]=”stackqueue”;
for(int i=0;i<strlen(sentence);i++)
pq.pqinsert(sentence[i]);
while(!pq.pqempty())
{ ch = pq.pqdelete();
while(!s.stackempty())
{ ch = s.pop(); cout<<ch; }
cout<<endl;
while(!q.qempty())
{ ch = q.qdelete();cout<<ch; }
cout<<endl; }
if ( isupper(ch) s.push(ch);
else q.qinsert(ch); }
七.(1)用preorder遍历一棵binary search tree得到序列 20 15 10 17 16 18 25 22 21 24 35给出这棵树,并给出postorder遍历.
(2) 说明函数f的作用
void inorderassign(treenode<int>*t,array<int>& a,int& i)
{
if(t!=null)
{
inoderassign(t->right(),a,i);
a[i++]=t->data;
inorderassign(t->left();a,i);
}
}
void f(array<int>& a)
{
binstree<int> tree;
for(int i=0;i<a.listsize();i++)
tree.insert(a[i]);
i=0;
inorderassign(tree.getroot(),a,i);
}
八. 说明函数pat的功能
int pat(char str[],int i)
{ int m=strlen(str)/2;
if(i>=m)return 1;
else if (str[i] !=str[m+i])return 0;
else return pat(str,i+1); }
字符串a 取
(a)“powwow” (b) “sees” (c) “123123”
(d) “123321”
分别给出 函数pat(a,0)的值.