Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

this is data structure class using c++ (for question number 1 don\'t write a ful

ID: 3874375 • Letter: T

Question

this is data structure class using c++
(for question number 1 don't write a full code but the answer the answer needed)

of 20% from the earned grade in this Test). (No exceptions) Write a C++ code to insert a node q on the right of the doubly linked node p in the given double linked list. (Each node has three members: data that contains the information, p->left represents the address of the node to the left of node p) 1. right and left members contain pointers to the nodes on either side. Ex. Dlist In an array based representation of a binary tree, what should be the maximum size of the array to accommodate the binary tree shown below? 2. 21 9 28 4 25 47 7 41 49

Explanation / Answer

//Please see the below code for question 1

#include<iostream>
using namespace std;

struct DLL
{
int data;
struct DLL *right;
struct DLL *left;
};


//newData is q, prev node is p
void insertAfter(struct DLL* prevNode, char newData)
{
    if (prevNode == NULL)
    {
        printf("wrong input prevNode should not be NULL");
        return;
    }

    /*allocate new node for data q */
    struct DLL* newNode =(struct DLL*) malloc(sizeof(struct DLL));

    /* Putting the data q */
    newNode->data = newData;

    /* set p->next to q->next */
    newNode->right = prevNode->right;

    /* set p->right to q */
    prevNode->right = newNode;

    /* set q->left to p */
    newNode->left = prevNode;

    /* q->right is not NULL set next node previous to q*/
    if (newNode->right != NULL)
      newNode->right->left = newNode;
}