Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- struct node
- {
- int data;
- node* next;
- }*head;
- void create_node(int n);
- void display_node();
- int main()
- {
- int n;
- printf("Please enter an positive integer for the number of node\n");
- scanf("%d",&n);
- create_node(n);
- display_node();
- return 0;
- }
- void create_node(int n)
- {
- int value,i;
- struct node *current,*temp;
- head=(struct node*)(malloc(sizeof(node)));
- printf("Please enter value for node : 1\n");
- scanf("%d",&value);
- head->data=value;
- head->next= nullptr;
- temp=head;
- for(i=2;i<=n;i++)
- {
- current=(struct node*)(malloc(sizeof(node)));
- printf("Please enter value for node : %d\n",i);
- scanf("%d",&value);
- current->data=value;
- current->next= nullptr;
- temp->next=current;
- temp=temp->next;
- }
- }
- void display_node()
- {
- struct node *temp;
- temp=head;
- while (temp!= nullptr)
- {
- printf("%d\t",temp->data);
- temp=temp->next;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement