Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- struct node
- {
- int data;
- struct node* next;
- };
- void push(struct node** head_ref, int new_data) // i understand the need of pointer to pointer here, since we are changing the actual value by adding a node..
- {
- struct node* new_node = (struct node*) malloc(sizeof(struct node));
- new_node->data = new_data;
- new_node->next = (*head_ref);
- (*head_ref) = new_node;
- }
- void insertAfter(struct node* prev_node, int new_data) // why are we not using pointer to pointer here since even here the pointer data is getting modified..??
- {
- if (prev_node == NULL)
- {
- return;
- }
- struct node* new_node =(struct node*) malloc(sizeof(struct node));
- new_node->data = new_data;
- new_node->next = prev_node->next;
- prev_node->next = new_node;
- }
- int main()
- {
- struct node* head = NULL;
- append(&head, 6);
- insertAfter(head->next, 8);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement