Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <assert.h>
- typedef struct Node
- {
- int value;
- struct Node *next
- } node;
- node* create_node(int data)
- {
- node *temp = (node *)malloc(sizeof(node));
- temp->value = data;
- temp->next = NULL;
- return temp;
- }
- void insert(node **head, node *link)
- {
- if(*head == NULL)
- {
- *head = link;
- return;
- }
- node *temp = *head;
- while(temp->next != NULL)
- {
- temp = temp->next;
- }
- temp->next = link;
- }
- void print_list(node *head)
- {
- node *temp = head;
- while(temp != NULL)
- {
- printf("%d-> " , temp->value);
- temp = temp->next;
- }
- }
- void main()
- {
- node *head = NULL;
- node *n1 = create_node(3);
- node *n2 = create_node(6);
- node *n3 = create_node(1);
- node *n4 = create_node(9);
- node *n5 = create_node(8);
- node *n6 = create_node(4);
- node *n7 = create_node(5);
- insert(&head, n1);
- insert(&head, n2);
- insert(&head, n3);
- insert(&head, n4);
- insert(&head, n5);
- insert(&head, n6);
- insert(&head, n7);
- print_list(head);
- }
Add Comment
Please, Sign In to add comment