DLL creation using recursion
#include <iostream>
using namespace std;
class Node
{
public:
int data;
Node *prev;
Node *next;
Node(int value)
{
data = value;
prev = NULL;
next = NULL;
}
};
Node *Create(int arr[], int index, int size, Node *back)
{
if (index == size)
{
return NULL;
}
else
{
Node *temp = new Node(arr[index]);
temp->prev = back;
temp->next = Create(arr, index + 1, size, temp);
return temp;
}
}
int main()
{
int arr[] = {12, 24, 36, 48};
Node *head = Create(arr, 0, 4, NULL);
Node *temp = head;
while (temp != NULL)
{
cout << temp->data << endl;
temp = temp->next;
}
return 0;
}