logo

Crowdly

Browser

Додати до Chrome

Disclaimer:  This question is significantly more challenging than the rest of th...

✅ Перевірена відповідь на це питання доступна нижче. Наші рішення, перевірені спільнотою, допомагають краще зрозуміти матеріал.

Disclaimer: This question is significantly more challenging than the rest of this exam. It is strongly recommended that you complete all other questions before attempting this question.

The level first order is a method of node insertion in a binary tree wherein the nodes are inserted from left to right at each level of the tree with an aim to completely fill up all the lower levels of the tree before considering the higher levels.  

For example: 

If the numbers 1 2 3 4 5 6 are inserted into a binary tree following the level first order, the resulting tree can be graphically depicted as follows:

Utilizing the skeleton code available at this link, complete the definition of the function insert_node_level_first() that inserts a node into a binary tree following the level first order.

void insert_node_level_first(struct node **rootPtr, struct queue_node** headPtr, int data)

The function has a return type of void and utilizes the following arguments:

  • rootPtr: address of the pointer to root node of the binary tree
  • headPtr: address of the pointer to first node of a queue that stores the address of nodes within the binary tree. The queue is utilized to support the binary tree node insertion based on the algorithm explained in the skeleton code.
  • data: the integer that should be inserted into the binary tree
The main() function within the skeleton code scans in 6 integers from the user through the terminal, calls the insert_node_level_first() function to insert the integers into the binary tree, and then prints the contents of the tree following the inOrder traversal scheme.  The skeleton code also contains the definition of push() and pop() functions that allow to push and pop nodes, respectively, in the queue that stores the address of the binary tree nodes. 

Rules for the task

  1. You should write your code only within the section specified in the skeleton code provided.
  2. You are not allowed to add, delete or modify any lines within the main(), push(), pop() and inOrder() functions in the skeleton code.
Note:

  1. In order to verify the functionality of your code within WSL environment in VS Code:
    • Download a copy of the test script run_tests.py and place it within the same folder as your .c file. 
    • Then, run the following commands sequentially on the terminal. The first command ensures that both the .c file and the compiled object file have the same name (your unique student ID, considered for example as 12345678). The second command runs the python test script by providing your student ID as input argument.

  2. Your code MUST be submitted as a .txt file below BEFORE the end of the test. Late submissions cannot be accepted.
  3. Your .txt file should be named as q9_studentID.txt, eg q9_12345678.txt

  4. You should use good programming practices

Більше питань подібних до цього

Хочете миттєвий доступ до всіх перевірених відповідей на learning.monash.edu?

Отримайте необмежений доступ до відповідей на екзаменаційні питання - встановіть розширення Crowdly зараз!

Browser

Додати до Chrome