-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlecturedsa5
47 lines (47 loc) · 873 Bytes
/
lecturedsa5
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include<stdio.h>
#include<stdlib.h>
struct Node{
int data;
struct Node* next;
};
struct Node* deletenode(struct Node* n1,int value){
struct Node* p1=n1;
struct Node* p2=n1->next;
while(p2!=NULL && p2->data!= value)
{
p1=p1->next;
p2=p2->next;
}
if(p1->data==value)
{
p1->next=p2->next;
free(p2);
}
return n1;
}
void printList(struct Node* p)
{
while (p != NULL) {
printf("%d \n",p->data);
p=p->next;
}
}
int main(){
struct Node* n1;
struct Node* n2;
struct Node* n3;
n1=(struct Node*)malloc(sizeof(struct Node));
n2=(struct Node*)malloc(sizeof(struct Node));
n3=(struct Node*)malloc(sizeof(struct Node));
n1->data=100;
n1->next=n2;
n2->data=200;
n2->next=n3;
n3->data=300;
n3->next=NULL;
printList(n1);
n1=deletenode(n1,200);
printf("=========\n");
printList(n1);
return 0;
}