diff --git a/LinkedList/DoubleLinkedList.cpp b/LinkedList/DoubleLinkedList.cpp new file mode 100644 index 00000000..982db145 --- /dev/null +++ b/LinkedList/DoubleLinkedList.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; +}