function [ ordert1 ] = ConnectNextCom( B,label1,k,t,orderk,ordert )
%UNTITLED3 Summary of this function goes here
%   Detailed explanation goes here
    [Q,w]=CalQ(B,label1);
    e=w+w';
    for i=1:size(w)(1)
        e(i,i)=e(i,i)/2;
    end
    x=orderk;
    y=ordert;
    if length(x)==1
        x(2)=x(1);
    end
    if length(y)==1
        ordert1=y;
        return
    end
    f=0;
    pk=k;
    pt=t;
    
    if abs(pk-pt)~=1
        fprintf('Error!!!\n')
        return
    else 
        if pk>pt
           f(1)=e(x(1),y(1))*(1/(e(x(1),x(1))+1/e(y(1),y(1))));
           f(2)=e(x(1),y(2))*(1/(e(x(1),x(1))+1/e(y(2),y(2))));
           if f(1)>f(2)
               ordert1=fliplr(y);
           else ordert1=y;
           end
        else
            f(1)=e(x(2),y(1))*(1/(e(x(2),x(2))+1/e(y(1),y(1))));
            f(2)=e(x(2),y(2))*(1/(e(x(2),x(2))+1/e(y(2),y(2))));
           if f(1)>f(2)
               ordert1=y;
           else ordert1=fliplr(y);
           end
        end
    end
      
end

