- Data Structures, doubly linked list, Linked List, Pointers

Find quadruplets with given sum in a Doubly Linked List

#include using namespace std;  struct Node {    int data;    struct Node *next, *prev;};  void insert(struct Node** head, int data){        struct Node* temp = new Node();          temp->data = data;    temp->next = temp->prev = NULL;      if ((*head) == NULL)        (*head) = temp;    else {        temp->next = *head;        (*head)->prev = temp;        (*head) = temp;    }}  void PrintFourSum(struct Node* head, int x){        struct Node* first = head;              struct Node* second;              struct Node* third;          struct Node* fourth = head;              while (fourth->next != NULL) {        fourth = fourth->next;    }              struct Node* temp;      while (first != NULL           && fourth != NULL           && first != fourth           && fourth->next != first) {                          second = first->next;          while (second != NULL               && fourth != NULL               && second != fourth               && fourth->next != second) {              int reqsum = x – (first->data                              + second->data);                                      third = second->next;                          temp = fourth;              while (third != NULL && temp != NULL                   && third != temp                   && temp->next != third) {                                  int twosum = third->data                             + temp->data;                                                  if (twosum == reqsum) {                      cout next;        }                          first = first->next;    }}  int main(){    struct Node* head = NULL;    insert(&head, 2);    insert(&head, 1);    insert(&head, 0);    insert(&head, 0);    insert(&head, -1);    insert(&head, -2);    int X = 0;    PrintFourSum(head, X);      return 0;}