Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- typedef struct my
- {
- int data;
- struct my *then;
- }my;
- my *head = NULL;
- int main()
- {
- int i,m,n,j=0;
- my *coming,*again;
- printf("Input the number of nodes : ");
- scanf("%d",&m);
- for(i=1;i<=m;i++)
- {
- printf("Inpute data for node %d : ",i);
- scanf("%d",&n);
- coming = malloc(sizeof(my));
- coming->data = n;
- coming->then = NULL;
- if(head==NULL)
- {
- head = coming;
- }
- else
- {
- again = head;
- while(again -> then != NULL)
- {
- again = again->then;
- }
- again->then = coming;
- }
- }
- again=head;
- printf("Data entered in the list are :\n");
- while(again!=NULL)
- {
- printf(" Data=%d\n",again->data);
- again=again->then;
- }
- printf("\nInput the number of data to insert in the beginning of the list : ");
- scanf("%d",&m);
- for(i=1;i<=m;i++)
- {
- printf("Inpute data for node %d : ",i);
- scanf("%d",&n);
- coming = malloc(sizeof(my));
- coming->data = n;
- coming->then = NULL;
- if(head==NULL)
- {
- head = coming;
- }
- else
- {
- coming->then = head;
- head = coming;
- }
- }
- coming=head;
- printf("\nData after inserted in the list are :\n");
- while(coming!=NULL)
- {
- printf(" Data=%d\n",coming->data);
- coming=coming->then;
- j++;
- }
- printf("Total Nodes: %d\n",j);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement