0% found this document useful (0 votes)
24 views2 pages

Recursive DLL Creation in C++

The document presents a C++ program that creates a doubly linked list (DLL) using recursion. It defines a Node class and a Create function that constructs the list from an array of integers. The main function initializes an array and displays the elements of the created DLL.

Uploaded by

sidk35510
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views2 pages

Recursive DLL Creation in C++

The document presents a C++ program that creates a doubly linked list (DLL) using recursion. It defines a Node class and a Create function that constructs the list from an array of integers. The main function initializes an array and displays the elements of the created DLL.

Uploaded by

sidk35510
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

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;
}

You might also like