Main

Monday, 26 November 2012

Solution of Assignment No.4 Of CS301 Due Date 03 dec 2012 Read more: Solution of Assignment No.4 Of CS301 Due Date 03 dec 2012 - Virtual University of cs301 datastructures solution-of-assignment-no-4-of-cs301-due-date-03-dec-2012

Instructions
Please read the following instructions carefully before solving & submitting assignment:
It should be clear that your assignment will not get any credit (zero marks) if:
  • The assignment is submitted after due date.
  • The submitted code does NOT compile.
  • The submitted assignment is other than .CPP file.
  • The submitted assignment does NOT open or file is corrupted.
  • The assignment is copied (from other student or ditto copy from handouts or internet).
Uploading instructions
For clarity and simplicity, You are required to Upload/Submit only ONE .CPP file.

Note: Use ONLY Dev-C++ IDE.
Objective
The objective of this assignment is

  • To make you familiar with Programming the Tree Data Structure.

For any query about the assignment, contact at cs301@vu.edu.pk
GOOD LUCK


Assignment Statement:                                              Marks: 20


A “Binary Search Tree” (BST) is a type of binary tree with the following property:

“Items in the left subtree are smaller than the root, and items in the right subtree are greater than the root”.



 Consider the following Binary Search Tree (BST):


                                                

Keeping in mind the property of Binary Search Tree (BST), Write a program in C++ which stores the above tree (BST) in computer memory and performs the following operations on the tree:

  1. Count total number of nodes in the tree
  2. Count number of leaf nodes in the tree
  3. Display value of each node using any of the traversal methods

Solution Guidelines:

Your Program should contain a BST class which should include the following functions:

  • insert_nodes( ) // to insert all nodes in the BST.
  • count_nodes( ) // to count total number of nodes in the tree
  • count_leaft_nodes( ) // to count number of leaf nodes in the tree
  • display( ) // to display nodes’ values on screen using any traversal methods (Preorder, Inorder, Postorder)

In main ( ) function, create an object of type “BST” and call above functions one by one against each operation.


 Sample Output:


Note: In sample output, values of nodes are displayed using preorder traversal.

No comments:

Post a Comment