Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdlib.h>
- #include <stdio.h>
- struct node1
- {
- int data;
- struct node1* next;
- };
- void add(int data, struct node1**head)
- {
- struct node1* p = *head;
- if(p == NULL)
- {
- p = (struct node1*)malloc(sizeof(struct node1));
- p->data = data;
- p->next = NULL;
- *head = p;
- return;
- }
- else
- {
- while (p->next)
- p = p->next;
- struct node1 *t = (struct node1*)malloc(sizeof(struct node1));
- t->data = data;
- t->next = NULL;
- p->next = t;
- }
- }
- void display(struct node1**head)
- {
- struct node1* p = *head;
- while (p)
- {
- printf("%d", p->data);
- p = p->next;
- }
- }
- int main()
- {
- struct node1* head = NULL;
- add(10, &head);
- add(20, &head);
- add(30, &head);
- display(&head);
- }
Add Comment
Please, Sign In to add comment