function correct = knn(A1, A2, B, class_B, k)
%Function uses A1 and A2 as training samples to do KNN classification
%A1 = samples from class  1
%A2 = samples from class -1
%B  = Test point
%class_B = Actual Class of B
%k = the parameter for K-nearest neighbour
%Correct = 1 if B is correctly classified
%Correct = 0 if B is incorrectly classified

correct=[];

dist_A1=abs(A1-B);
dist_A2=abs(A2-B);

for i=1:size(k,2)
    r=0;
    
    k_class_1=0; k_class_2=0;    
    while k_class_1 + k_class_2 < k(i)
        r=r+0.01;
        k_class_1=sum(dist_A1<=r);
        k_class_2=sum(dist_A2<=r);
    end
    
    if k_class_1 >=k_class_2
        reco_class=1;
    else
        reco_class=-1;
    end
    
    if reco_class==class_B
        correct=[correct 1];
    else
        correct=[correct 0];
    end
end

