Functions for inorder-preorder and postorder traversals


Question 1) This assignment deals with creating multi-linked list data structure for storing and processing student's academic data. To keep problem simple, this program would deal with only rollnumbers. The type of roll-numbers we deal with are also restricted as described below.
A roll-no comprises of an 8-digit integer. The first 2 digits indicate the year of joining ( E.g. 1998 would be coded as 98, ignore the y2K problem ). The 3rd , 4th and 5th digits indicate the department where the program is offered. Sample values are given below. 108 : IT 109 : Electronics 104 : Civil 107 : Computer 105 : Elec 102 : Mech 6th digit indicates male or female student. Male=0 and female=1.

7th digit is for category for admission. The last 2 digits denote the serial number of the student. It should be clear from above that given a roll number of a student, one can find out certain details about the student.

(a) A list of roll-numbers would be given to you in a file ( say file, "input"); how many such numbers are there are not known apriori. You have to process the roll-numbers and create a multi-linked data structure as explained below:

A node of this structure has 3 fields : i) rollno ii) a link field, say dept_link and iii) another link field, say prog_link. The dept_link links this node to another node that has the same dept code ( 4th and 5th digits ). Similarly the prog_link links this node to another node that has the same program code ( 3rd digit ). The last node in the chain for a department or program would have a NULL value respectively.

This multi-linked structure would be accessed using 2 arrays, dept array and prog array. Each element of these arrays is of type pointer to node. Note that every rollno exists on two lists, one linked via the dept code and the other linked via the program code. For the following roll-numbers, the data structure to be constructed is shown on a separate page. Input : 041051122

(b) Given a dept code, your program should list all roll nos belonging to that department. Similarly given a program code, your program should list all students registered for the program.

Question 2) Given a list of integers, construct a binary search tree from the list. You may use any algorithm for constructing the tree. Use a linked list representation for the tree where each node has two pointers, one for the left subtree and the other for the right subtree and an integer field. The binary tree is to be accessed by a pointer to the root of the tree.

a. Use a header file say "btree.h" to place the class definition of a binary tree. Incorporate appropriate function and data members for using a binary tree. A separate main() is to be used for solving the programming problem.

b. After constructing the search tree, read in a few values (some which exist in the tree and some which don't ) and search the tree for these values. In case of the value being found, output a string of the form, LLRLR. This string would indicate the path followed from root in the tree leading to the value. For example, the string LRLL for a value say 20 would indicate that 20 was found by proceeding from the root as follows:

Left (L); Right(R); Left(L); Left(L). Note that such string is a unique signature for any element present in the tree.

c) Write down three non-member functions for inorder, preorder and postorder traversals of binary search tree. For the tree constructed in part(b)above, demonstrate the result of all the three traversals.

Request for Solution File

Ask an Expert for Answer!!
Data Structure & Algorithms: Functions for inorder-preorder and postorder traversals
Reference No:- TGS06641

Expected delivery within 24 Hours