loading...

CS301 VU Assignment No. 2 Spring 2012 Solution

Assignment Statement: Marks: 20

Suppose some VU campuses are connected to a central server placed at Lahore campus via leased lines such that each campus has a one hop (direct) connectivity to the central server or it has multi hop connection to Lahore campus via other campuses at provincial head quarters or regional campuses which are in turn connected to the Lahore Campus.

Here is a table showing campus names and assumed codes.

Campus Code
Lahore 18
Islamabad 95
Rawalpindi 29
Peshawar 41
Fateh Jang 52
Chakwal 74
Karachi 86
Haiderabad 33
Quetta 57
Badeen 20
Zob 17

Below is the Binary Tree showing the leased line spanning in which each node contains one campus code while the edges show the direct connectivity between two campuses.

Write a C++ program to store this Binary Tree in computer memory in which each node has the campus code as value (campus name storing is excluded for the sake of simplicity).

Also print on screen, the post order traversal of stored binary tree in order to verify your solution.

Solution Guidelines:
> In coding there must be a class to create and manipulate tree nodes.
> There should be a function to create (store) this binary tree from two of its traversals given below.
> In main ( ) function, use two arrays to store Preorder and Inorder traversals of the given binary tree.

Hint:
Use Preorder and Inorder Traversals of the Binary Tree for solving.

Write on paper, a manual Postorder traversal of the tree to see your screen printed Postorder traversal with it, for verification of your solution correctness.

[Preorder: 18 95 41 29 52 74 86 33 57 17 20]
[Inorder: 41 95 74 52 29 18 86 57 17 33 20]

Solution: This is Just a Idea Solution run the code in compiler and check with above values.



DOWNLOAD SOLUTION HERE
loading...