DS FinalRevision
DS FinalRevision
A. Given the shown Circular Queue of size 8. Execute the following code on the
shown queue, then do the following:
1. Re-draw the queue after code execution to show changes.
2. Show the new positions of Front and Rear as shown.
dequeue( );
dequeue( );
dequeue( );
enqueue( 100);
enqueue( 50);
Answer:
B. Given the Array-based queue Implementation, Trace the following C++ code,
given that Queue SIZE is 5. Write down the results of each displayQueue() and
showfront() functions exist in this code:
Programs:
1. Suppose you have a Queue q, containing various items, another stack s,
containing various items and an empty auxiliary queue r. Write a function
that adds stack s elements to the top of the queue q with the same order.
Answer:
Stack s
7
6
5
Queue q
1 2 3
7 6 5 1 2 3
Answer:
Queue q
1 2 3
x=1
2 3
x=2
3
x=3
3
3 2
3 2 1
Linked List
A. In the following single linked list, write code to add a new node at the
start node.
Answer:
void LinkedList<DataType>::insert( DataType & element )
{
Node<DataType> *newNode =new Node<DataType>;
newNode->info = element ;
newNode->next = start ;
start = newNode;
}
B. Complete the missing parts in the following Simple Link List according
to its working strategy.
Answer:
D. In the following single linked list, write code to make the single list
empty
Answer:
LinkedList<DataType>::makeEmpty( )
{
while ( start != NULL )
{
current = start; // starts from the beginning
start = start->next;
delete current;
}
current = NULL;
}
E. Complete the missing parts in the following Doubly Circular Link List
according to its working strategy.
Answer:
Tree
A. Draw the expression tree for the following expressions, then calculate
their results using the created trees in detailed steps:
1. 17 * 3 + 2 - (10 * 9 / 3) + 3 * 4
2. ( ( ( 6 + 4 ) * 9) / ( 8 – 1) ) ^( (2 + 5 ) – 4 )
B. What is the degree and the depth for those created trees?
Answer:
1. 17 * 3 + 2 - (10 * 9 / 3) + 3 * 4
Degree: 2
Depth: 4
2. ( ( ( 6 + 4 ) * 9) / ( 8 –
1) ) ^ ( (2 + 5 ) – 4)
Degree: 2
Depth: 4
// Create node containing 20, and link up its right and left subtrees
intTreePtr bt4(new intTree);
bt4->insert(20);
bt4->makeLeft(bt3); //15
bt4->makeRight(bt2); //7
// ** done creating right subtree
25,36,30,20,40,10,22,48,28,5,38,12
1- Remove node 10 from the original tree then re-draw the tree.
2- Remove node 36 from the original tree then re-draw the tree.
Note: Show details in creation and removal
Answer:
1- Remove node 10
2- Remove node 36
Search and sort