Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- typedef struct node {
- int data;
- struct node* next;
- } node;
- void printer(node* head) {
- while (head) {
- printf("%d\n", head->data);
- head = head->next;
- }
- }
- node* pop (node* head) {
- if (head->next == NULL) return NULL;
- }
- int removeEl(node** head, int n)
- {
- node* prev = NULL;
- node* curr = *head;
- while (curr != NULL && curr->data != n) {
- prev = curr;
- curr = curr->next;
- }
- if (curr->data == n) {
- if (curr == *head) {
- *head = curr->next;
- }
- else {
- prev->next = prev->next->next;
- }
- return 1;
- }
- else {
- return -1;
- }
- }
- int main(void){
- node head;
- node *headp = &head;
- head.data = 5;
- node n2;
- n2.data = 6;
- node n3;
- n3.data = 2;
- n3.next = NULL;
- n2.next = &n3;
- head.next = &n2;
- removeEl(&headp, 2);
- printer(headp);
- }
Advertisement
Add Comment
Please, Sign In to add comment