Академический Документы
Профессиональный Документы
Культура Документы
11 Data Structures
http://ecomputernotes.com
http://ecomputernotes.com
Priority Queue
#include "Event.cpp" #define PQMAX 30 class PriorityQueue { public: PriorityQueue() { size = 0; rear = -1; }; ~PriorityQueue() {}; int full(void) { return ( size == PQMAX ) ? 1 : 0; };
http://ecomputernotes.com
Priority Queue
Event* remove() { if( size > 0 ) { Event* e = nodes[0]; for(int j=0; j < size-2; j++ ) nodes[j] = nodes[j+1];
http://ecomputernotes.com
Priority Queue
int insert(Event* e) { if( !full() ) { rear = rear+1; nodes[rear] = e; size = size + 1; sortElements(); // in ascending order return 1; } cout << "insert queue is full." << endl; return 0; }; int length() { return size; }; };
http://ecomputernotes.com
Sohail Aslam
Javed Aslam
Yasmeen Aslam
Haaris
Saad
Qasim
Asim
Fahd
Ahmad
Sara
Omer
http://ecomputernotes.com
http://ecomputernotes.com
Binary Tree
A binary tree is a finite set of elements that is either empty or is partitioned into three disjoint subsets. The first subset contains a single element called the root of the tree. The other two subsets are themselves binary trees called the left and right subtrees. Each element of a binary tree is called a node of the tree.
http://ecomputernotes.com
Binary Tree
Binary tree with 9 nodes.
A B C
http://ecomputernotes.com
Binary Tree
root A B C
Left subtree
Right subtree
http://ecomputernotes.com
Binary Tree
Recursive definition
A root B C
Left subtree
Right subtree
http://ecomputernotes.com
Binary Tree
Recursive definition
A B root D E C
Left subtree
http://ecomputernotes.com
Binary Tree
Recursive definition
A B C
E root G
http://ecomputernotes.com
Binary Tree
Recursive definition
A root B C
Right subtree
http://ecomputernotes.com
Binary Tree
Recursive definition
A B C root D E
Left subtree
Right subtree
http://ecomputernotes.com
Not a Tree
Structures that are not trees.
A B C
http://ecomputernotes.com
Not a Tree
Structures that are not trees.
A B C
http://ecomputernotes.com
Not a Tree
Structures that are not trees.
A B C
http://ecomputernotes.com
Leaf nodes
http://ecomputernotes.com
Leaf nodes
Binary Tree
If every non-leaf node in a binary tree has nonempty left and right subtrees, the tree is termed a strictly binary tree.
A B C
http://ecomputernotes.com
The depth of a binary tree is the maximum level of any leaf in the tree.
http://ecomputernotes.com
A B 1
Level 0
C 1
Level 1
D 2
E 2
F 2
Level 2
G 3
H 3
I 3
Level 3
http://ecomputernotes.com
C 1
D 2
E 2
F 2
G 2
H 3
J 3
L 3
M 3
N 3
O 3
http://ecomputernotes.com
Level 2: 22 nodes
Level 3: 23 nodes
http://ecomputernotes.com
In a complete binary tree, there are 2d leaf nodes and (2d - 1) non-leaf (inner) nodes.
http://ecomputernotes.com
http://ecomputernotes.com
http://ecomputernotes.com