Untitled
unknown
plain_text
a year ago
1.2 kB
8
Indexable
#include<stdio.h> #include<stdlib.h> struct Node{ int data; struct Node* next; }; struct Node* addData(struct Node *head, int serchData, int data){ struct Node * ptr = (struct Node *) malloc(sizeof(struct Node)); struct Node * p = head; ptr->data = data; while(p != NULL){ if(p->data == serchData){ ptr->next = p->next; p->next = ptr; } p = p->next; } } int main(){ struct Node* node1; node1 = malloc(sizeof(struct Node)); node1->data = 30; node1->next = NULL; struct Node* node2; node2 = malloc(sizeof(struct Node)); node2->data = 50; node2->next = NULL; node1->next = node2; struct Node* node3; node3 = malloc(sizeof(struct Node)); node3->data = 80; node3->next = NULL; node2->next = node3; struct Node* head = node1; addData(head,50,44); showNodeData(head); return 0; } void showNodeData(struct Node* head){ struct Node* node = head; while(node != NULL){ printf("%d ", node->data); node = node->next; } }
Editor is loading...
Leave a Comment