Question
ADDS Practical Exam Please download the adds-pe.cpp file from the following URL and make changes to answer these three questions. You should only upload the
ADDS Practical Exam
Please download the adds-pe.cpp file from the following URL and make changes to answer these three questions.
You should only upload the modified adds-pe.cpp file to your svn repositoryand submit to the websubmission system. The test script will compile your code using g++ -o main.out -std=c++11 -O2 -Wall *.cpp.
In this practical exam, you are asked to realise the following three operations based on the given data structure. The example output of each function is given in the source file.
Question 1: (1 mark for style, 2 mark for functionality)
Please fill in the function Node* add(Node* head, int val) which accepts a head pointer to a list and an integer. A new node is created with the given value and added to the front of the list. The new head pointer is returned.
Question 2: (1 mark for style, 2 mark for functionality)
Please fill in the function void printOdd(Node* head) which accept a head pointer to a list and print out the elements in odd position using std::cout. The head node is defined to be in position 1.
Question 3: (1 mark for style, 3 mark for functionality)
Please fill in the function void clear(Node* n1, Node* n2). In this function, n1 and n2 pointing to two nodes in the same list. Your task is to remove all nodes between these two nodes. And for all deleted nodes, you need to free the memory in the heap.
If there is no node in between n1 and n2, your function should do nothing.
adds-pe-1.cpp 1 includeStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started