SHOW:
|
|
- or go back to the newest paste.
| 1 | #include<iostream> | |
| 2 | using namespace std; | |
| 3 | void push(int x); | |
| 4 | ||
| 5 | typedef struct alvi | |
| 6 | {
| |
| 7 | int data; | |
| 8 | ||
| 9 | struct alvi *next; | |
| 10 | struct alvi *prev; | |
| 11 | }node; | |
| 12 | node *head=NULL; | |
| 13 | ||
| 14 | int main() | |
| 15 | {
| |
| 16 | push(1); | |
| 17 | push(2); | |
| 18 | push(3); | |
| 19 | return 0; | |
| 20 | } | |
| 21 | void push(int x) | |
| 22 | {
| |
| 23 | node *newNode = new node(); | |
| 24 | newNode->data = x; | |
| 25 | if(head==NULL) | |
| 26 | {
| |
| 27 | cout<<"First node pushed"<<endl; | |
| 28 | newNode->prev=NULL; | |
| 29 | newNode->next=NULL; | |
| 30 | head=newNode; | |
| 31 | } | |
| 32 | else | |
| 33 | {
| |
| 34 | cout<<"other node pushed"<<endl; | |
| 35 | newNode->prev=NULL; | |
| 36 | newNode->next=head; | |
| 37 | head= newNode; | |
| 38 | } | |
| 39 | } |