Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<stdlib.h>
- typedef struct node
- {
- int value;
- struct node *next;
- }node;
- node *head=NULL;
- void insertlast(int x)
- {
- node *n=(node*)malloc(sizeof(node));
- n->next=NULL;
- n->value=x;
- node *list=head;
- if(head==NULL) head=n;
- else{
- while(list->next!=NULL)
- {
- list=list->next;
- }
- list->next=n;
- }
- return;
- }
- void display()
- {
- node *list=head;
- printf("Data entered in the list:\n");
- while(list!=NULL){
- printf("Data = %d\n",list->value);
- list=list->next;
- }
- }
- int main()
- {
- int i,n,x;
- printf("Enter how many value you want to enter: ");
- scanf("%d",&n);
- printf("\n\n");
- for(i=1;i<=n;i++)
- {
- scanf("%d",&x);
- insertlast(x);
- }
- display();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement