CSc 17
Test 2
24 June 1999
Page 1
>>>>>>>>>>>>>>>>ANSWERS<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
1.
(15 pts) (a) Using the standard algorithm for building a binary
tree for storing numbers in order: (1) show the state of the tree
after the numbers 15, 12, 14, 6, and 9 have been added to an empty
tree in that order;
(2) then show the state of the tree after the
numbers 8, 17, and 16 have also been added to the tree in that order.
15
15
/
/
\
12
12
17
/
\
/
\
/
6
14
6
14
16
\
\
9
9
/
8
(b)
Given the binary tree
2
/
\
/
\
3
9
/
\
/
\
19
7
8
3
list the numbers resulting from
(1) an inorder search of the tree
19 3 7 2 8 9 3
(2) a postorder search of the tree
19 7 3 8 3 9 2
(3) a preorder search of the tree
2 3 19 7 9 8 3
2.
(10 pts)
What is the output when the following code is executed?
char s[]="one\ntwo\nthree", t[20];
for(int j=0;j<12;j++)
t[j]=s[j];
t[3]='';
t[8]='\0';
cout<<t;
//onetwo
int *x;
x=new int[10];
for(int j=0;j<10;j++)
x[j]=j*j;
cout<<endl<<(x+3)[4]<<" "<<(x3)[4]<<endl;
//49 1
int f,*g,*h,j;
f=4;
g=&f;
h=g;
*g=9;
*h=8;
cout<<f<<" "<<*g;
//8 8
This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document3.
(25 pts)
This is the end of the preview.
Sign up
to
access the rest of the document.
 Spring '08
 varies
 Bubble Sort, Selection Sort, Comparison sort, Cocktail sort

Click to edit the document details