-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
117 lines (99 loc) · 2.52 KB
/
main.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdbool.h>
#include <math.h>
#include"kdTree.h"
#include"stack.h"
#include"helper.h"
#define N 1000
int k;
int count=0;
int arr[N];
extern int c1;
extern int c2;
int min(int a, int b)
{
if (a <= b) return a;
else return b;
}
int main()
{
// comment the below line if you want an interactive console
FILE *fileptr;
fileptr = fopen("input.txt", "r");
// for interactive console
struct node *root = NULL;
//printf("Enter dimension : ");
fscanf(fileptr,"%d", &k);
printf("%d\n",k);
int n;
// printf("Enter number of points : ");
fscanf(fileptr,"%d", &n);
printf("%d\n",n);
int neighbours;
//printf("Enter number of neighbours : ");
fscanf(fileptr,"%d", &neighbours);
printf("%d",neighbours);
for (int i = 0; i < n; i++)
{
//printf("Enter %d th set of data point : ", i + 1);
for (int i = 0; i < k; i++)
{
fscanf(fileptr,"%d", &arr[i]);
}
root = insert_main(root, arr);
}
// printf("Enter the set of data point you want to find : ");
int find[k-1];
for (int i = 0; i < k-1; i++)
{
fscanf(fileptr,"%d", &find[i]);
}
//printf("\n");
if (search_main(root, find))
{
printf("\nFound\n");
}
else
{
printf("\nNot found\n");
}
int req = min(neighbours, count);
printf("The %d closest data points related to this data point are : \n", neighbours);
for (int i = 0; i < req; i++)
{
pop();
}
//display_array();
count_1();
//printf("%d %d",c1,c2);
if(c1>c2){
if(search_main(root, find)){
printf("\nPredicted Outcome %d",1);
printf("Original Outcome %d",root->point[k-1]);
}
else{
printf("\nPredicted Outcome %d",1);
}
}
else if(c1<c2){
if(search_main(root, find)){
printf("\nPredicted Outcome %d",0);
printf("Original Outcome %d",root->point[k-1]);
}
else{
printf("\nPredicted Outcome %d",0);
}
}
else{
if(search_main(root, find)){
printf("\nPredicted Outcome %d/%d",0,1);
printf("Original Outcome %d",root->point[k-1]);
}
else{
printf("\nPredicted Outcome %d/%d",0,1);
}
}
return 0;
}