0% found this document useful (0 votes)
8 views

DS Module 3

Uploaded by

jeevithar048
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

DS Module 3

Uploaded by

jeevithar048
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 29

Data Structure & Applications – BCS304

MODULE 3

LINKED LISTS

ADDITIONAL LIST OPERATIONS

Operations for Chains

It is often necessary, and desirable, to build a variety of functions for manipulating singly linked lists.
Some that we have seen already are get-node and ret-node, which get and return nodes to the available
space list. Inverting (or reversing) a chain
This routine is especially interesting because we can do it "in place” if we use three pointers. We use
the following declarations:

The function with at least three examples, an empty list and lists of one and two nodes, so that you
understand how it works. For a list of length > 1 nodes, the while loop is executed length times and so
the computing time is linear or O(length). Another useful function is one that concatenates two chains,
ptr1\ and ptr2. The complexity of this function is O(length of list ptr1). Since this function does not
allocate additional storage for the new list, ptr1 also contains the concatenated list. (The exercises
explore a concatenation function that does not alter ptr1.)

Operations For Circularly Linked Lists

Now let us take another look at circular lists like the one in Figure 4.16. Suppose we want to insert a
new node at the front of this list. We have to change the link field of the node containing This means
that we must move down the entire length of a until we find the last node. It is more convenient if the
name of the circular list points to the last node rather than the first (Figure 4.16). Now we can write
functions that insert a node at the front (Figure 4.17) or at the rear of a circular list in a fixed amount
of time. To insert node at the rear, we only need to add the additional statement = node to the else
clause of insert-front (Program 4.19). As a last example of a simple function for circular lists, we
write a function (Program 4.20) that determines the length of such a list.
Data Structure & Applications – BCS304
Data Structure & Applications – BCS304
Data Structure & Applications – BCS304

SPARSE MATRIX REPRESENTATION

A linked list representation for sparse matrices.

In data representation, each column of a sparse matrix is represented as a circularly linked list
with a header node. A similar representation is used for each row of a sparse matrix.
Each node has a tag field, which is used to distinguish between header nodes and entry nodes.

Header Node:
 Each header node has three fields: down, right, and next as shown in figure (a).
 The down field is used to link into a column list and the right field to link into a row list.
 The next field links the header nodes together.
 The header node for row i is also the header node for column i, and the total number of
header nodes is max {number of rows, number of columns}.

Element node:
 Each element node has five fields in addition in addition to the tag field: row, col, down,
right, value as shown in figure (b).
 The down field is used to link to the next nonzero term in the same column and the right
field to link to the next nonzero term in the same row. Thus, if a ij ≠ 0, there is a node with
tag field = entry, value = aij, row = i, and col = j as shown infigure (c).
 We link this node into the circular linked lists for row i and column j. Hence, it is
simultaneously linked into two different lists.

Consider the sparse matrix, as shown in below figure (2).


Data Structure & Applications – BCS304

Figure (3) shows the linked representation of this matrix. Although we have not shown the value
of the tag fields, we can easily determine these values from the node structure.
For each nonzero term of a, have one entry node that is in exactly one row list and one column list.
The header nodes are marked HO-H3. As the figure shows, we use the right field of the header node
list header to link into the list of headernodes.

To represent a numRows x numCols matrix with numTerms nonzero terms, then we need max
numRows, numCols} + numTerms + 1 nodes. While each node may require several words of
memory, the total storage will be less than numRows x numCols when numTerms is
sufficiently small.

There are two different types of nodes in representation, so unions are used to create the
appropriate data structure. The C declarations are as follows:
Data Structure & Applications – BCS304

#define MAX-SIZE 50 /*size of largest matrix*/


typedef enum {head, entry} tagfield;
typedef struet matrixNode *matrixPointer;

typedef strue {
int row; int
eol; int value;
} entryNode;

typedef struet {
matrixPointer down;
matrixPointer right; tagfield
tag;
}
union {
matrixPointer next;
entryNode entry;
}

DOUBLY LINKED LIST


1. The difficulties with single linked lists is that, it is possible to traversal only in one direction,
ie., direction of the links.
2. The only way to find the node that precedes p is to start at the beginning of the list. The same
problem arises when one wishes to delete an arbitrary node from a singly linked list. Hence
the solution is to use doubly linkedlist

Doubly linked list: It is a linear collection of data elements, called nodes, where each node N
is divided into three parts:
1. An information field INFO which contains the data of N
2. A pointer field LLINK (FORW) which contains the location of the next node in the list
3. A pointer field RLINK (BACK) which contains the location of the preceding node in
the list

The declarations are:


typedef struct node *nodePointer;
typedef struct {
nodePointer llink;
element data;
nodePointer rlink;
} node;
Data Structure & Applications – BCS304

Insertion into a doubly linked list


Insertion into a doubly linked list is fairly easy. Assume there are two nodes, node and newnode,
node may be either a header node or an interior node in a list. The function dinsert performs the
insertion operation in constant time.

void dinsert(nodePointer node, nodePointer newnode)


{/* insert newnode to the right of node */
newnode→llink = node;
newnode→rlink = node→rlink;
node→rlink→llink = newnode;
node→rlink = newnode;
}
Program: Insertion into a doubly linked circular list

Deletion from a doubly linked list


Deletion from a doubly linked list is equally easy. The function ddelete deletes the node deleted
from the list pointed to by node.
To accomplish this deletion, we only need to change the link fields of the nodes that precede
(deleted→llink→rlink) and follow (deleted→rlink→llink) the node we want to delete.

void ddelete(nodePointer node, nodePointer deleted)


{/* delete from the doubly linked list */
if (node == deleted)
printf("Deletion of header node not permitted.\n");
else {
deleted→llink→rlink = deleted→rlink;
deleted→rlink→llink = deleted→llink;
free(deleted) ;
}
}

Program: Deletion from a doubly linked circular list

HEADER - LINKED LISTS

A header linked list is a linked list which contains a special node, called the header node, at the
beginning of the list.
The following are two kinds of widely used header lists:
1. A grounded header list is a header list where the last node contains the null pointer.
2. A circular header list is a header list where the last node points back to the headernode.
Data Structure & Applications – BCS304

Below figure contains schematic diagrams of these header lists.

Observe that the list pointer START always points to the header node.
 If START→LINK = NULL indicates that a grounded header list is empty
 If START→LINK = START indicates that a circular header list is empty.

The first node in a header list is the node following the header node, and the location of the first
node is START→LINK, not START, as with ordinary linked lists.
Below algorithm, which uses a pointer variable PTR to traverse a circular header list
1. Begins with PTR = START→LINK (not PTR = START)
2. Ends when PTR = START (not PTR = NULL).

Algorithm: (Traversing a Circular Header List) Let LIST be a circular header list in memory.
This algorithm traverses LIST, applying an operation PROCESS to each node of LIST.
1. Set PTR: = START→LINK. [Initializes the pointer PTR.]
2. Repeat Steps 3 and 4 while PTR ≠ START:
3. Apply PROCESS to PTR→INFO.
4. Set PTR: = PTR→LINK. [PTR now points to the next node.]
[End of Step 2 loop.]
5. Exit.

Algorithm: SRCHHL (INFO, LINK, START, ITEM, LOC)


LIST is a circular header list in memory. This algorithm finds the location LOC of the node
where ITEM first appears in LIST or sets LOC = NULL.
1. Set PTR: = START→LINK
2. Repeat while PTR→INFO [PTR] ≠ ITEM and PTR ≠ START:
Set PTR: =PTR→LINK. [PTR now points to the next node.]
[End of loop.]
3. If PTR→INFO = ITEM, then:
Set LOC: = PTR.
Else:
Set LOC: = NULL.
[End of If structure.]
4. Exit.
Data Structure & Applications – BCS304

The two properties of circular header lists:


1. The null pointer is not used, and hence all pointers contain valid addresses.
2. Every (ordinary) node has a predecessor, so the first node may not require a special case.

There are two other variations of linked lists


1. A linked list whose last node points back to the first node instead of containing the null
pointer, called a circular list
2. A linked list which contains both a special header node at the beginning of the list and a
special trailer node at the end of thelist

TREES

DEFINITION
A tree is a finite set of one or more nodes such that
 There is a specially designated node called root.
 The remaining nodes are partitioned into n >= 0 disjoint set T1,…,Tn, where each of
these sets is a tree. T1,…,Tn are called the subtrees of the root.

Every node in the tree is the root of some subtree


Data Structure & Applications – BCS304

TERMINOLOGY
 Node: The item of information plus the branches to other nodes
 Degree: The number of subtrees of a node
 Degree of a tree: The maximum of the degree of the nodes in the tree.
 Terminal nodes (or leaf): nodes that have degree zero or node with no successor
 Nonterminal nodes: nodes that don’t belong to terminal nodes.
 Parent and Children: Suppose N is a node in T with left successor S1 and right
successor S2, then N is called the Parent (or father) of S1 and S2. Here, S1 is called
left child (or Son) and S2 is called right child (or Son) of N.
 Siblings: Children of the same parent are said to be siblings.
 Edge: A line drawn from node N of a T to a successor is called an edge
 Path: A sequence of consecutive edges from node N to a node M is called a path.
 Ancestors of a node: All the nodes along the path from the root to that node.
 The level of a node: defined by letting the root be at level zero. If a node is at level l,
then it children are at level l+1.
 Height (or depth): The maximum level of any node in the tree

Example
Data Structure & Applications – BCS304

A is the root node


B is the parent of E and F
C and D are the sibling of B
E and F are the children of B
K, L, F, G, M, I, J are external nodes, or leaves
A, B, C, D, E, H are internal nodes
The level of E is 3
The height (depth) of the tree is 4
The degree of node B is 2
The degree of the tree is 3
The ancestors of node M is A, D, H
The descendants of node D is H, I, J, M

Representation of Trees
There are several ways to represent a given tree such as:

Figure (A)

1. List Representation
2. Left Child- Right Sibling Representation
3. Representation as a Degree-Two tree
Data Structure & Applications – BCS304

List Representation:

The tree can be represented as a List. The tree of figure (A) could be written as the list.
(A (B (E (K, L), F), C (G), D (H (M), I, J) ) )

 The information in the root node comes first.


 The root node is followed by a list of the subtrees of that node.

Tree node is represented by a memory node that has fields for the data and pointers to the tree
node's children

Since the degree of each tree node may be different, so memory nodes with a varying number
of pointer fields are used.
For a tree of degree k, the node structure can be represented as below figure. Each child field
is used to point to a subtree.

Left Child-Right Sibling Representation

The below figure show the node structure used in the left child-right sibling representation

To convert the tree of Figure (A) into this representation:


1. First note that every node has at most one leftmost child
2. At most one closest right sibling.
Data Structure & Applications – BCS304

Ex:
 In Figure (A), the leftmost child of A is B, and the leftmost child of D is H.
 The closest right sibling of B is C, and the closest right sibling of H is I.
 Choose the nodes based on how the tree is drawn. The left child field of each node points to
its leftmost child (if any), and the right sibling field points to its closest right sibling (if
any).
Figure (D) shows the tree of Figure (A) redrawn using the left child-right sibling representation.

Figure (D): Left child-right sibling representation of tree of figure (A)

Representation as a Degree-Two Tree

To obtain the degree-two tree representation of a tree, simply rotate the right-sibling pointers in
a left child-right sibling tree clockwise by 45 degrees. This gives us the degree-two tree displayed
in Figure (E).

Figure (E): degree-two representation

In the degree-two representation, a node has two children as the left and right children.
Data Structure & Applications – BCS304

BINARY TREES
Definition: A binary tree T is defined as a finite set of nodes such that,
 T is empty or
 T consists of a root and two disjoint binary trees called the left subtree and the right
subtree.

Figure: Binary Tree

Different kinds of Binary Tree

1. Skewed Tree
A skewed tree is a tree, skewed to the left or skews to the right.
or
It is a tree consisting of only left subtree or only right subtree.
 A tree with only left subtrees is called Left Skewed Binary Tree.
 A tree with only right subtrees is called Right Skewed Binary Tree.

2. Complete Binary Tree


A binary tree T is said to complete if all its levels, except possibly the last level, have the maximum
number node 2i, i ≥ 0 and if all the nodes at the last level appears as far left as possible.

Figure (a): Skewed binary tree Figure (b): Complete binarytree


Data Structure & Applications – BCS304

3. Full Binary Tree


A full binary tree of depth ‘k’ is a binary tree of depth k having 2k – 1 nodes, k ≥ 1.

Figure: Full binary tree of level 4 with sequential node number

4. Extended Binary Trees or 2-trees


An extended binary tree is a transformation of any binary tree into a complete binary tree.
This transformation consists of replacing every null subtree of the original tree with
“special nodes.” The nodes from the original tree are then internal nodes, while the special
nodes are external nodes.

For instance, consider the following binary tree.

The following tree is its extended binary tree. The circles represent internal nodes, and square
represent external nodes.
Every internal node in the extended tree has exactly two children, and every external node is
a leaf. The result is a complete binary tree.
Data Structure & Applications – BCS304

PROPERTIES OF BINARY TREES

Lemma 1: [Maximum number of nodes]:


(1) The maximum number of nodes on level i of a binary tree is 2 i-1, i ≥ 1.
(2) The maximum number of nodes in a binary tree of depth k is 2k -1, k ≥ 1.

Proof:
(1) The proof is by induction on i.
Induction Base: The root is the only node on level i = 1. Hence, the maximum number of nodes
on level i =1 is 2 i-1 = 20 = 1.
Induction Hypothesis: Let i be an arbitrary positive integer greater than 1. Assume that the
maximum number of nodes on level i -1is 2i-2
Induction Step: The maximum number of nodes on level i -1 is 2i-2 by the induction hypothesis.
Since each node in a binary tree has a maximum degree of 2, the maximum number of nodes on
level i is two times the maximum number of nodes on level i-1, or 2i-1

(2) The maximum number of nodes in a binary tree of depth k is


k k
∑ (maximum number of nodes on level i) = ∑ 2i-1 = 2k-1
i=0 i=0

Lemma 2: [Relation between number of leaf nodes and degree-2 nodes]:


For any nonempty binary tree, T, if n 0 is the number of leaf nodes and n2 the number of nodes of
degree 2, then n0 = n2 + 1.

Proof: Let n1 be the number of nodes of degree one and n the total number of nodes.
Since all nodes in T are at most of degree two, we have
n = n0 + n1+ n2 (1)
Count the number of branches in a binary tree. If B is the number of branches, then
n =B + 1.
All branches stem from a node of degree one or two. Thus,
B =n 1+ 2n2.
Hence, we obtain
n = B + 1= n 1+ 2n2 + 1 (2)

Subtracting Eq. (2) from Eq. (1) and rearranging terms, we get

n0 = n2 +1
Data Structure & Applications – BCS304

Consider the figure:

Here, For Figure (b) n2=4, n0= n2+1= 4+1=5


Therefore, the total number of leaf node=5

BINARY TREE REPRESENTATION


The storage representation of binary trees can be classified as
1. Array representation
2. Linked representation.

Array representation:
 A tree can be represented using an array, which is called sequential representation.
 The nodes are numbered from 1 to n, and one dimensional array can be used to store
the nodes.
 Position 0 of this array is left empty and the node numbered i is mapped to position i of
the array.

Below figure shows the array representation for both the trees of figure (a).
Data Structure & Applications – BCS304

 For complete binary tree the array representation is ideal, as no space is wasted.
 For the skewed tree less than half the array is utilized.

Linked representation:
The problems in array representation are:
 It is good for complete binary trees, but more memory is wasted for skewed and many
other binary trees.
 The insertion and deletion of nodes from the middle of a tree require the movement of
many nodes to reflect the change in level number of these nodes.

These problems can be easily overcome by linked representation

Each node has three fields,


 LeftChild - which contains the address of left subtree
 RightChild - which contains the address of right subtree.
 Data - which contains the actual information

C Code for node:

typedef struct node *treepointer;


typedef struct {
int data;
treepointer leftChild, rightChild;
}node;
Data Structure & Applications – BCS304

Figure: Node representation

Linked representation of the binary tree


Data Structure & Applications – BCS304

BINARY TREE TRAVERSALS

Visiting each node in a tree exactly once is called tree traversal

The different methods of traversing a binary tree are:


1. Preorder
2. Inorder
3. Postorder
4. Iterative inorder Traversal
5. Level-Order traversal

1. Inorder: Inorder traversal calls for moving down the tree toward the left until you cannot go
further. Then visit the node, move one node to the right and continue. If no move can be done, then
go back one more node.

Let ptr is the pointer which contains the location of the node N currently being scanned.
L(N) denotes the leftchild of node N and R(N) is the right child of node N

Recursion function:
The inorder traversal of a binary tree can be recursively defined as

 Traverse the left subtree in inorder.


 Visit the root.
 Traverse the right subtree in inorder.

void inorder(treepointerptr)
{
if (ptr)
{
inorder (ptr→leftchild);
printf (“%d”,ptr→data);
inorder (ptr→rightchild);
}
}
Data Structure & Applications – BCS304

2. Preorder: Preorder is the procedure of visiting a node, traverse left and continue. When you
cannot continue, move right and begin again or move back until you can move right and resume.

Recursion function:
The Preorder traversal of a binary tree can be recursively defined as
 Visit the root
 Traverse the left subtree in preorder.
 Traverse the right subtree in preorder

void preorder (treepointerptr)


{
if (ptr)
{
printf (“%d”,ptr→data)
preorder (ptr→leftchild);
preorder (ptr→rightchild);
}
}

3. Postorder: Postorder traversal calls for moving down the tree towards the left until you can
go no further. Then move to the right node and then visit the node and continue.
Recursion function:
The Postorder traversal of a binary tree can be recursively defined as
 Traverse the left subtree in postorder.
 Traverse the right subtree in postorder.
 Visit the root

void postorder(treepointerptr)
{
if (ptr)
{
postorder (ptr→leftchild);
postorder (ptr→rightchild);
printf (“%d”,ptr→data);
}
}
Data Structure & Applications – BCS304

4. Iterative inorder Traversal:


Iterative inorder traversal explicitly make use of stack function.
The left nodes are pushed into stack until a null node is reached, the node is then removed from the
stack and displayed, and the node’s right child is stacked until a null node is reached. The traversal
then continues with the left child. The traversal is complete when the stack is empty.

5. Level-Order traversal:
Visiting the nodes using the ordering suggested by the node numbering is called level
ordering traversing.
The nodes in a tree are numbered starting with the root on level 1 and so on.
Firstly visit the root, then the root’s left child, followed by the root’s right child. Thus
continuing in this manner, visiting the nodes at each new level from the leftmost node to the
rightmost node.

Level order traversal: 1 2 3 4 5


Initially in the code for level order add the root to the queue. The function operates by
deleting the node at the front of the queue, printing the nodes data field and adding the nodes left
and right children to the queue.
Data Structure & Applications – BCS304

Function for level order traversal of a binary tree:

ADDITIONAL BINARY TREE OPERATIONS

1. Copying a Binarytree
This operations will perform a copying of one binary tree to another.

C function to copy a binary tree:

treepointer copy(treepointer original)


{ if(original)
{ MALLOC(temp,sizeof(*temp));
temp→leftchild=copy(original→leftchild);
temp→rightchild=copy(original→rightchild);
temp→data=original→data;
return temp;
}
return NULL;
}

2. Testing Equality
This operation will determin the equivalance of two binary tree. Equivalance binary tree have
the same strucutre and the same information in the corresponding nodes.
Data Structure & Applications – BCS304

C function for testing equality of a binary tree:


int equal(treepointer first,treepointer second)
{
return((!first && !second) || (first && second && (first→data==second→data)
&& equal(first→leftchild,second→leftchild) && equal(first→rightchild,
second→rightchild))
}

This function will return TRUE if two trees are equivalent and FALSE if they are not.

3. The Satisfiability problem


 Consider the formula that is constructed by set of variables: x1, x2, …, xn and operators
(and), (or), ¬ (not).
 The variables can hold only of two possible values, true or false.
 The expression can form using these variables and operators is defined by the
following rules.
 A variable is an expression
 If x and y are expressions, then ¬x, x y, x y are expressions
 Parentheses can be used to alter the normal order of evaluation (¬ > > )

Example: x1 (x2 ¬ x3) If x1 and x3 are false and x2 is true


= false (true ¬false)
= false true
= true

The satisfiablity problem for formulas of the propositional calculus asks if there is an
assignment of values to the variable that causes the value of the expression to be true.

Let’s assume the formula in a binary tree


(x1 ¬x2) (¬ x1 x3) ¬x3
Data Structure & Applications – BCS304

The inorder traversal of this tree is


x1 ¬x2 ¬ x1 x3 ¬x3

The algorithm to determine satisfiablity is to let (x1, x2, x3) takes on all the possible
combination of true and false values to check the formula for each combination.

For n value of an expression, there are 2n possible combinations of true and false
For example n=3, the eight combinations are (t,t,t), (t,t,f), (t,f,t), (t,f,f), (f,t,t), (f,t,f), (f,f,t),
(f,f,f).
The algorithm will take O(g 2n), where g is the time to substitute values for x1, x2,… xn and
evaluate the expression.

Node structure:
For the purpose of evaluation algorithm, assume each node has four fields:

Define this node structure in C as:

Satisfiability function: The first version of Satisfiability algorithm


Data Structure & Applications – BCS304

THREADED BINARY TREE

The limitations of binary tree are:


 In binary tree, there are n+1 null links out of 2n totallinks.
 Traversing a tree with binary tree is time consuming.
These limitations can be overcome by threaded binary tree.

In the linked representation of any binary tree, there are more null links than actual pointers. These
null links are replaced by the pointers, called threads, which points to other nodes in the tree.

To construct the threads use the following rules:


1. Assume that ptr represents a node. If ptr→leftChild is null, then replace the null link
with a pointer to the inorder predecessor of ptr.
2. If ptr →rightChild is null, replace the null link with a pointer to the inorder successor of
ptr.
Ex: Consider the binary tree as shown in below figure:

Figure A: Binary Tree


There should be no loose threads in threaded binary tree. But in Figure B two threads have
been left dangling: one in the left child of H, the other in the right child of G.

Figure B: Threaded tree corresponding to Figure A


In above figure the new threads are drawn in broken lines. This tree has 9 node and 10 0 -links
which has been replaced by threads.
Data Structure & Applications – BCS304

When trees are represented in memory, it should be able to distinguish between threads and
pointers. This can be done by adding two additional fields to node structure, ie., leftThread and
rightThread
 If ptr→leftThread = TRUE, then ptr→leftChild contains a thread, otherwise it contains a
pointer to the left child.
 If ptr→rightThread = TRUE, then ptr→rightChild contains a thread, otherwise it contains
a pointer to the rightchild.

Node Structure:
The node structure is given in C declaration

typedef struct threadTree *threadPointer typedef struct{


short int leftThread; threadPointer
leftChild; char data;
threadPointer rightChild; short int
rightThread;
}threadTree;

The complete memory representation for the tree of figure is shown in Figure C
Data Structure & Applications – BCS304

The variable root points to the header node of the tree, while root →leftChild points to the start
of the first node of the actual tree. This is true for all threaded trees. Here the problem of the loose
threads is handled by pointing to the head node called root.

Inorder Traversal of a Threaded Binary Tree


 By using the threads, an inorder traversal can be performed without making use of a
stack.
 For any node, ptr, in a threaded binary tree, if ptr→rightThread =TRUE, the inorder
successor of ptr is ptr →rightChild by definition of the threads. Otherwise we
obtain the inorder successor of ptr by following a path of left-child links from the
right- child of ptr until we reach a node with leftThread = TRUE.
 The function insucc ( ) finds the inorder successor of any node in a threaded tree
without using a stack.

threadedpointer insucc(threadedPointer tree)


{ /* find the inorder successor of tree in a threaded binary tree */
threadedpointer temp;
temp = tree→rightChild;
if (!tree→rightThread)
while (!temp→leftThread)
temp = temp→leftChild;
return temp;
Program: Finding inorder successor of a node

To perform inorder traversal make repeated calls to insucc ( ) function

void tinorder (threadedpointer tree)


{
Threadedpointer temp = tree;
for(; ;){
temp = insucc(temp);
if (temp == tree) break;
printf(“%3c”, temp→data
}
}
Program: Inorder traversal of a threaded binary tree
Data Structure & Applications – BCS304

Inserting a Node into a Threaded Binary Tree


In this case, the insertion of r as the right child of a node s is studied.
The cases for insertion are:
 If s has an empty right subtree, then the insertion is simple and diagrammed in Figure
 If the right subtree of s is not empty, then this right subtree is made the right subtree of r
after insertion. When this is done, r becomes the inorder predecessor of a node that has a
leftThread == true field, and consequently there is a thread which has to be updated to
point to r. The node containing this thread was previously the inorder successor of s.

void insertRight(threadedPointer Sf threadedPointer r)


{ /* insert r as the right child of s */
threadedpointer temp;
r→rightChild = parent→rightChild;
r→rightThread = parent→rightThread;
r→leftChild = parent;
r→leftThread = TRUE;
s→rightChild = child;
s→rightThread = FALSE;
if (!r→rightThread) {
temp = insucc(r);
temp→leftChild = r;
}
}

You might also like