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)
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;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.