Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- //structure with two fields
- struct node
- {
- int data;
- struct node *next;
- };
- // data type definition
- typedef struct node node;
- //pointer to node which initially set to NULL
- node *head=NULL;
- //fucntion create and display
- void create(int num);
- void display();
- main()
- {
- int n,i,num;
- printf("enter the no of nodes : ");
- scanf ("%d",&n);
- for(i=0;i<n;++i)
- {
- printf("enter the data : ");
- scanf("%d",&num);
- create(num);
- }
- display();
- }
- void create(int num)
- {
- printf("n");
- if(head==NULL)
- {
- node *temp=(node*)malloc(sizeof(node));
- temp->data=num;
- temp->next=head;
- head=temp;
- }
- else
- {
- node *temp1=head;
- while(temp1!=NULL)
- {
- temp1=temp1->next;
- }
- node *ptr=(node*)malloc(sizeof(node));
- ptr->data=num;
- ptr->next=temp1->next;
- temp1->next=ptr;
- }
- }
- void display()
- {
- node *temp;
- temp=head;
- printf("list is : ");
- while(temp!=NULL)
- {
- printf("%d->",temp->data);
- temp=temp->next;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement