Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I NEED AN ANSWER FOR THIS Create a process hierarchy tree as a memory-allocated array table of length n which references processes, indexed 0 to

I NEED AN ANSWER FOR THIS

Create a process hierarchy tree as a memory-allocated array table of length n which references processes, indexed 0 to n-1 (n must be 1 or higher in value). Each process is a structure consisting of four fields: parent: a process index corresponding to the current process creator first_child: the first child process (if any) of the current process older_sibling: a process (if any) that was created immediately before the current process and shares the same parent younger_sibling: a process (if any) that was created immediately after the current process and shares the same parent All process fields are initialized to invalid values of -1. In addition, process 0 has its parent field set to itself (0), which therefore activates the process as the "root" of the hierarchy. Once the data is initialized, have a loop statement act as the main program control. This loop will prompt the user for an integer value as a menu selection. The last selection will exit the loop statement, with an else (or default) case detecting out-of-bounds selections. Once the loop has been completed, the array must have its memory deallocated before the program can end. The necessary functions (not including main) are simplified as follows: print_table() represents the table-printing function, which displays each active process in table (having a valid parent field). Every row represents a process, and every column represents a separate process field (see sample output below for examples). create_processes() represents the create function, which prompts for the parent process located in table at parent_index (values 0 to n-1 for active processes). The function creates a new child process (for parent_index) located in table at child_index by performing the following: Record the parent's index, parent_index, in table[child_index] Initialize the first_child and younger_sibling fields of table[child_index] to be -1 (empty) Record the older_sibling field of table[child_index] as youngest_sibling, which is the index location of the current youngest sibling process (soon to be previous) Record the younger_sibling field of table[youngest_sibling] (notice the different between the words 'younger' and 'youngest') as child_index, In the event that table[parent_index] does not have any children (first_child is empty), then skip the recording of older_sibling and younger_sibling - instead, assign the first_child field of table[parent_index] as child_index destroy_processes() represents the base destroy function, which prompts for the parent process located in table at parent_index. The base function calls upon a recursive destroy function destroy_process_recursively() that recursively destroys all descendent processes (child, grandchild, etc.) from table[parent_index] by performing the following tasks: The initially call the recursive function on the first_child field of table[parent_index] The recursive function receives any field as current_index which represents the index location of the process in table that is to be destroyed Call the recursive function on the younger_sibling field of table[current_index] (this continues until the youngest sibling is reached) Call the recursive function on the first_child field of table[current_index] (this means that sibling processes are destroyed before children processes for any given process) Set all fields of table[current_index] to the empty value of -1 (parent, first_child, younger_sibling,older_sibling) What NOT to do (any violation will result in an automatic score of 0 on the assignment): Do NOT modify the integer values for the menu selection choices (1,2,3,4) - the test script used for grading your assignment will not work correctly. IN C PLEASE

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Intelligent Information And Database Systems Second International Conference Acids Hue City Vietnam March 2010 Proceedings Part 1 Lnai 5990

Authors: Manh Thanh Le ,Jerzy Swiatek ,Ngoc Thanh Nguyen

2010th Edition

3642121446, 978-3642121449

Students also viewed these Databases questions

Question

c. What were you expected to do when you grew up?

Answered: 1 week ago

Question

4. Describe how cultural values influence communication.

Answered: 1 week ago

Question

3. Identify and describe nine cultural value orientations.

Answered: 1 week ago