-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathFIN2555-question2-solution.c
More file actions
42 lines (28 loc) · 930 Bytes
/
FIN2555-question2-solution.c
File metadata and controls
42 lines (28 loc) · 930 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// TYPE_NODEPTR == TYPE_NODE*
int CopyAVLTree(TYPE_NODEPTR T1,TYPE_NODEPTR *T2){
// Note: T2 is pointer point to TYPE_NODEPTR
if(!T1){
//if(T1 == NULL)
return 0;
}
(*T2) = NewNode(T1 -> Info);
CopyAVLTree(T1 -> Left, &((*T2) -> Left));
CopyAVLTree(T1 -> Right, &((*T2) -> Right));
// & ( (*T2) -> Left ) == address of (*T2) -> Left
// "&(*T2)->Left" has same meaning because "->" has higher order than &
if((*T2) -> Left){
(*T2) -> Left -> Parent = (*T2);
}
if((*T2) -> Right){
(*T2) -> Right -> Parent = (*T2);
}
/* Use these instead of line 14 - 26.
if( CopyAVLTree(T1 -> Left, &((*T2) -> Left)) ){
(*T2) -> Left -> Parent = (*T2);
}
if( CopyAVLTree(T1 -> Right, &((*T2) -> Right)) ){
(*T2) -> Right -> Parent = (*T2);
}
*/
return 1;
}