Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<stdlib.h>
- struct node
- {
- int data;
- struct node *prev,*next;
- }*head;
- int main()
- {
- int n;
- printf("Enter Total Number Of Nodes: ");
- scanf("%d",&n);
- createList(n);
- printf("\Doubly Linked List is: ");
- displayList();
- return 0;
- }
- void createList(int n)
- {
- int i,data;
- struct node *temp,*p;
- temp=(struct node *)malloc(sizeof(struct node));
- printf("Enter data for node 1: ");
- scanf("%d",&data);
- temp->data=data;
- temp->prev=NULL;
- temp->next=NULL;
- head=temp;
- p=temp;
- for(i=2;i<=n;i++)
- {
- temp=(struct node *)malloc(sizeof(struct node));
- printf("Enter data for node %d: ",i);
- scanf("%d",&data);
- temp->data=data;
- temp->next=NULL;
- temp->prev=p;
- p->next=temp;
- p=p->next;
- }
- }
- void displayList()
- {
- struct node *temp;
- temp=head;
- while(temp != NULL)
- {
- printf("\n%d",temp->data);
- temp=temp->next;
- }
- }
Add Comment
Please, Sign In to add comment