File tree 1 file changed +43
-0
lines changed
1 file changed +43
-0
lines changed Original file line number Diff line number Diff line change
1
+ #include < iostream>
2
+ using namespace std ;
3
+
4
+ // creating struct Node
5
+
6
+ struct Node {
7
+ int data;
8
+ struct Node *prev;
9
+ struct Node *next;
10
+ };
11
+ struct Node * head = NULL ;
12
+
13
+ // Inserting new node
14
+
15
+ void insert (int newdata) {
16
+ struct Node * newnode = (struct Node *) malloc (sizeof (struct Node ));
17
+ newnode->data = newdata;
18
+ newnode->prev = NULL ;
19
+ newnode->next = head;
20
+ if (head != NULL )
21
+ head->prev = newnode ;
22
+ head = newnode;
23
+ }
24
+ // display linked list
25
+
26
+ void display () {
27
+ struct Node * ptr;
28
+ ptr = head;
29
+ while (ptr != NULL ) {
30
+ cout<< ptr->data <<" " ;
31
+ ptr = ptr->next ;
32
+ }
33
+ }
34
+ int main () {
35
+ insert (3 );
36
+ insert (1 );
37
+ insert (7 );
38
+ insert (2 );
39
+ insert (9 );
40
+ cout<<" The doubly linked list is: " ;
41
+ display ();
42
+ return 0 ;
43
+ }
You can’t perform that action at this time.
0 commit comments