From f76eed8d549f275e800f65bfa797a1e8f21c2b58 Mon Sep 17 00:00:00 2001 From: amar123666 <78369248+amar123666@users.noreply.github.com> Date: Mon, 4 Oct 2021 09:38:10 +0530 Subject: [PATCH] Implementation of doubly linked list --- Linked Lists/Implementationofdublyll.cpp | 35 ++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 Linked Lists/Implementationofdublyll.cpp diff --git a/Linked Lists/Implementationofdublyll.cpp b/Linked Lists/Implementationofdublyll.cpp new file mode 100644 index 0000000..982db14 --- /dev/null +++ b/Linked Lists/Implementationofdublyll.cpp @@ -0,0 +1,35 @@ +#include +using namespace std; +struct Node { + int data; + struct Node *prev; + struct Node *next; +}; +struct Node* head = NULL; +void insert(int newdata) { + struct Node* newnode = (struct Node*) malloc(sizeof(struct Node)); + newnode->data = newdata; + newnode->prev = NULL; + newnode->next = head; + if(head != NULL) + head->prev = newnode ; + head = newnode; +} +void display() { + struct Node* ptr; + ptr = head; + while(ptr != NULL) { + cout<< ptr->data <<" "; + ptr = ptr->next; + } +} +int main() { + insert(3); + insert(1); + insert(7); + insert(2); + insert(9); + cout<<"The doubly linked list is: "; + display(); + return 0; +}