-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlist.c
More file actions
71 lines (59 loc) · 1.06 KB
/
list.c
File metadata and controls
71 lines (59 loc) · 1.06 KB
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
71
#include <stdio.h>
#include <stdlib.h>
typedef struct node
{
int number;
struct node *next;
}
node;
bool search(node *tree, int target);
int main(int argc, char *argv[])
{
node *list = NULL;
for (int i = 1; i < argc; i++)
{
int number = atoi(argv[i]);
node *n = malloc(sizeof(node));
if ( n == NULL )
{
return 1;
}
n->number = number;
n->next = NULL;
n->next = list;
list = n;
}
node *ptr = list;
while(ptr != NULL)
{
printf("%i\n", ptr->number);
ptr = ptr->next;
}
ptr = list;
while ( ptr ! = NULL)
{
node *next = ptr->next;
free(ptr);
ptr = next;
}
}
bool search(node *tree, int target)
{
if(tree == NULL)
{
return false;
}
else if (target < tree->number)
{
return search(tree->left, target);
}
else if (target > tree->number)
{
return search(tree->right, target);
}
else
{
return true;
}
return false
}