#include <iostream>

using namespace std;

// Data structure to represent a node with

struct Node

{

int data;

Node* next;

Node* down;

Node(int data)

{

this->data = data;

this->next = this->down = nullptr;

}

};

// Utility function to print a list with down and next pointers

{

return;

cout << ‘ ‘ << head->data << ‘ ‘;

cout << “[“;

cout << “]”;

}

}

// Utility function to print a linked list

{

cout << head->data << ” -> “;

}

cout << “null” << ‘n’;

}

// Recursive function to a linked list

{

// base case

return nullptr;

// keep track of the next pointer

// the down list first

// go to the last node

while (tail->next) {

tail = tail->next;

}

// process the next list after the down list

tail->next = flattenList(next);

}

// main function

int main()

{

// create individual nodes first and link them together later

Node* one = new Node(1);

Node* two = new Node(2);

Node* three = new Node(3);

Node* four = new Node(4);

Node* five = new Node();

Node* six = new Node(6);

Node* seven = new Node(7);

Node* eight = new Node(8);

Node* nine = new Node(9);

Node* ten = new Node();

Node* eleven = new Node(11);

Node* twelve = new Node(12);

Node* thirteen = new Node(13);

Node* fourteen = new Node(14);

Node* fifteen = new Node(15);

// set next pointers

one->next = four;

four->next = fourteen;

fourteen->next = fifteen;

five->next = nine;

nine->next = ten;

seven->next = eight;

eleven->next = thirteen;

// set down pointers

one->down = two;

two->down = three;

four->down = five;

five->down = six;

six->down = seven;

ten->down = eleven;

eleven->down = twelve;

cout << “The Original list is :” << ‘n’;