Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<stdlib.h>
- typedef struct linkList
- {
- int data;
- struct linkList *next;
- struct linkList *prev;
- } node;
- node *last;
- void createlinklist(node *t,int n)
- {
- int i, data;
- if(n >= 1)
- {
- printf("Input data for node-1 : ");
- scanf("%d", &data);
- t->data = data;
- t->next = NULL;
- t->prev = NULL;
- for(i=2; i<=n; i++)
- {
- printf("Input data for node-%d : ", i);
- scanf("%d", &data);
- node *newnode = (node*)malloc(sizeof(node));
- newnode->data = data;
- newnode->next = NULL;
- newnode->prev = t;
- t->next = newnode;
- t = t->next;
- if(i==n){
- last=t;
- printf("D = %p T = %p\n",last,t);
- }
- }
- }
- }
- void display(node *t)
- {
- printf("\nPrint the link list form first to last: ");
- printf("%d ", t->data);
- while (t->next!= NULL)
- {
- t = t->next;
- printf("%d ", t->data);
- }
- printf("\nPrint the link list form last to first: ");
- printf("%d ", last->data);
- while (last->prev != NULL)
- {
- last = last->prev;
- printf("%d ", last->data);
- }
- }
- int main()
- {
- int n;
- node *first = (node*)malloc(sizeof(node));
- printf("How many node do you want to create? - ");
- scanf("%d", &n);
- createlinklist(first,n);
- printf("Another First D = %d\n",first->data);
- printf("Another Last D = %d",last->data);
- display(first);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement