bin tree

closed account (STR9GNh0)
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

BEGIN highestAmount ( pNode)
DEFINE wordBST: pointer of RECORD wordNode;
DEFINE RECORD LetterNode 
{ 
	left: 	 pointer of RECORD wordNode, 
	word: 	 char, 
	counter: integer, 
	right: 	 pointer of RECORD wordNode 
} 

DEFINE Q;
CreateQueue(Q);
SET wordBST to pNode;
SET Highest TO pNode -> counter;

WHILE (wordBST is not null)
process (wordBST)

IF (wordBST -> left is not null) THEN
	ENQUEUE(Q, wordBST -> left)
ENDIF
	
IF (wordBST  ->  right is not null) THEN
	ENQUEUE(Q, wordBST -> right)
ENDIF

IF (not isEmpty(Q));
IF (wordBST -> counter is greater than Highest) THEN
	SET Highest TO wordBST -> counter;
ELSE 
	swapNode (wordBST, pNode);
ENDIF
	SET wordBST to DEQUEUE (Q);
ELSE
	SET wordBST to null
ENDIF
ENDWHILE
END highestAmount 


the above is a pseudo code to traverse the binary tree to get the highest occurrence from a counter and output the word.

do advise am i thinking it correctly, thanks
Last edited on
closed account (STR9GNh0)
anyone ?
Topic archived. No new replies allowed.