Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<stdlib.h>
- struct linkedlist
- {
- int num;
- int *ptr;
- int *pre_ptr;
- };
- typedef struct linkedlist node;
- int main()
- {
- node *first,*head,*temp=0,*previous=0;
- int count=0,option=1;
- first=0;
- while(option)
- {
- head=(node*)malloc(sizeof(node));
- printf("we get memory address: %d\n",head);
- printf("Enter the number: ");
- scanf("%d",&head->num);
- if(first!=0)
- {
- temp->ptr=head;
- head->pre_ptr=temp;
- temp=head;
- }
- else
- {
- temp=first=head;
- }
- fflush(stdin);
- printf("Press 1 to continue or press 0 to stop: ");
- scanf("%d",&option);
- }
- temp->ptr=0;
- temp=first;
- while(temp!=0)
- {
- printf("[%d] [%d][%d]",temp,previous,temp->num);
- temp=temp->ptr;
- previous=temp->pre_ptr;
- count++;
- }
- printf("[NULL]\n");
- printf("Total number of nodes: %d",count);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement