-
Notifications
You must be signed in to change notification settings - Fork 0
/
serach in DLL.c
70 lines (67 loc) · 1.66 KB
/
serach in DLL.c
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/******************************************************************************
Online C Compiler.
Code, Compile, Run and Debug C program online.
Write your code in this editor and press "Run" button to compile and execute it.
*******************************************************************************/
#include <stdio.h>
#include<stdlib.h>
struct node
{
struct node *prev_link;
int data;
struct node *next_link;
};
void travers(struct node *head);
void search(struct node *head, int search);
void main()
{
struct node *head=(struct node*)malloc(sizeof(struct node));
head->prev_link=NULL;
head->data=10;
head->next_link=NULL;
struct node *current=(struct node*)malloc(sizeof(struct node));
current->prev_link=NULL;
current->data=20;
current->next_link=NULL;
head->next_link=current;
current=(struct node*)malloc(sizeof(struct node));
current->prev_link=NULL;
current->data=30;
current->next_link=NULL;
head->next_link->next_link=current;
printf("before reversing\n");
travers(head);
search(head,20);
}
void travers(struct node *head)
{
struct node *temp=NULL;
temp=head;
if(head==NULL)
{
printf("link is empty\n");
}
while(temp!=NULL)
{
printf("%d<=>",temp->data);
temp=temp->next_link;
}
printf("NULL\n");
}
void search(struct node *head,int search)
{
struct node *temp=NULL;
temp=head;
while(head!=NULL)
{
if(temp->data==search)
{
printf("serach=%d",search);
break;
}
else
{
temp=temp->next_link;
}
}
}