2021-04-11 17:48:29 +00:00
|
|
|
|
#include <bits/stdc++.h>
|
2021-02-09 13:24:16 +00:00
|
|
|
|
#include <iostream>
|
|
|
|
|
using namespace std;
|
|
|
|
|
struct Node {
|
2021-04-11 17:48:29 +00:00
|
|
|
|
int data;
|
|
|
|
|
struct Node *prev;
|
|
|
|
|
struct Node *next;
|
2021-02-09 13:24:16 +00:00
|
|
|
|
};
|
|
|
|
|
struct Node* head = NULL;
|
|
|
|
|
void insert(int newdata) {
|
2021-04-11 17:48:29 +00:00
|
|
|
|
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;
|
2021-02-09 13:24:16 +00:00
|
|
|
|
}
|
|
|
|
|
void display() {
|
2021-04-11 17:48:29 +00:00
|
|
|
|
struct Node* ptr;
|
|
|
|
|
ptr = head;
|
|
|
|
|
while(ptr != NULL) {
|
|
|
|
|
cout<< ptr->data <<" ";
|
|
|
|
|
ptr = ptr->next;
|
|
|
|
|
}
|
2021-02-09 13:24:16 +00:00
|
|
|
|
}
|
|
|
|
|
int main() {
|
2021-04-11 17:48:29 +00:00
|
|
|
|
insert(3);
|
|
|
|
|
insert(1);
|
|
|
|
|
insert(7);
|
|
|
|
|
insert(2);
|
|
|
|
|
insert(9);
|
|
|
|
|
cout<<"The doubly linked list is: ";
|
|
|
|
|
display();
|
|
|
|
|
return 0;
|
2021-02-09 13:24:16 +00:00
|
|
|
|
}
|