diff --git a/Data Structures/DoublyLinkedList.cpp b/Data Structures/DoublyLinkedList.cpp new file mode 100644 index 0000000..09cb412 --- /dev/null +++ b/Data Structures/DoublyLinkedList.cpp @@ -0,0 +1,34 @@ +#include +using namespace std; + +class Node { + int data; + Node* prev; + Node* next; + + //constructor + Node(int d ) { + this-> data = d; + this->prev = NULL; + this->next = NULL; + } +} + +//traversing a linked list +void print(Node* head) { + Node* temp = head ; + + while(temp != NULL) { + cout << temp -> data << " "; + temp = temp -> next; + } + cout << endl; +} + +int main() { + Node* node1 = new Node(10); + Node* head = node1; + print(head); + + return 0; +}