Can someone check my answer too these questions and make sure they are right? Th
ID: 3597195 • Letter: C
Question
Can someone check my answer too these questions and make sure they are right? This is in c++. Thank you so much!!
Suppose that head1 and tail1 are pointers of type node and they point respectively to the first and the last nodes of a link list. Suppose also that head2 is a pointer of type node and points to the first node of a second link list. Write code that will merge the two link lists and make head2 point to the first node of the merged list. You can use the node class and the link list toolkit in the book your code. DO NOT USE LOOPS (6) to write headl 2 Suppose p_ptr is a pointer to an object of type node and that it points to a node in a link list. Also suppose that value is an object of type value_type. Write code, in detail, to insert value after p ptr in the link list showing all the steps necessary. Your code cannot just be a function call Correct the two errors in the following function. The function name conveys the intended purpose of the function (8) int* GetRawPointer(unique_ptr uptr) return uptr; @wn um,qu(,Explanation / Answer
6.
tail1->set_link(head2);
head2 = head1;
head1 = NULL;
// now comes tricky part
// if you dont want to retain tail1
tail1 = NULL;
// otherwise travel in seocnd list to get tail
while(tail1->next != NULL) {
tail1 = tail1->next;
}
7.
value need not be init, it is given as value_type
void insertAfter(struct node *ptr_node_A, value_type value) {
struct node *n_ptr_node = (struct ndoe *) malloc (sizeof(struct node));
n_ptr_node->Y = value; // make sure your field name is named as Y, I don't ahve your node class so really cant be sure
n_ptr_node->next = ptr_node_A->next;
ptr_node_A->next = n_ptr_node;
}
int main() {
....
insertAfter(p_ptr, val);
...
}
8.
This can't be checked withput having knowledge of rest of the code.