Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<stdlib.h>
- typedef struct Node
- {
- int a;
- struct Node *next,*prev;
- }node;
- node*head=NULL,*tail=NULL;
- void insert_first (int an)
- {
- node*N=(node*)malloc(sizeof(node));
- N->a=an;
- N->next=NULL;
- N->prev=NULL;
- if(head==NULL){
- head=N;
- tail=N;
- }
- else{
- head->prev=N;
- N->next=head;
- head=N;
- }
- }
- void display_first()
- {
- node*list=head;
- if(head==NULL)
- {
- printf("No Data Available\n");
- }
- else
- {
- while(list!=NULL)
- {
- printf("%d\n",list->a);
- list=list->next;
- }
- }
- }
- int main(){
- int n,x,i;
- head=NULL;
- printf("Input the Number of Node:");
- scanf("%d",&n);
- for(i=0;i<n;i++){
- scanf("%d",&x);
- insert_first(x);
- }
- display_first();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment