selvavijay1987 0 Newbie Poster

Dear Sir/Madam/Friends,

Sir, i have written code for first step of euclidean distance . now i need to merge the smallest distance points as single point. The class which i have written is

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Collections;

/// <summary>
/// Summary description for CreatingDistanceMatrix
/// </summary>
public class CreatingDistanceMatrix
{
    DataSet ds;
    DataTable dtsource;
    public ArrayList p1, p2;
    public DataTable dt;
    public double smallval;
    public CreatingDistanceMatrix(DataSet ds)
    {
        this.ds = ds;
        dtsource = ds.Tables[0];
        CrateDisMat();
        GetPair();
    }

    private void GetPair()
    {
        p1 = new ArrayList();
        p2 = new ArrayList();
        p1.Clear();
        p2.Clear();
        double temp1 = 0;
        for (int i = 0; i < dt.Rows.Count; i++)
        {
            for (int j = i; j < dt.Columns.Count; j++)
            {
                temp1 = Convert.ToDouble(dt.Rows[i][j]);
                if (temp1 == smallval)
                {
                    p1.Add(i);
                    p2.Add(j);
                }
            }
        }
    }

    private void CrateDisMat()
    {
        dt = new DataTable();
        smallval = 0;
        double temp, temp1;
        bool flage = true;
        double sum = 0;

        for (int i = 0; i < dtsource.Rows.Count; i++)
        {
            DataColumn dc = new DataColumn(i.ToString(), typeof(double));
            dt.Columns.Add(dc);
        }

        for (int i = 0; i < dtsource.Rows.Count; i++)
        {
            //DataRow dr = new DataRow(i);
            dt.Rows.Add(i);
        }

        for (int i = 0; i < dtsource.Rows.Count; i++)
        {
            for (int j = 0; j < dtsource.Rows.Count; j++)
            {
                //sum = 0;
                for (int k = 0; k < dtsource.Columns.Count; k++)
                {
                    temp = Convert.ToDouble(dtsource.Rows[i][k]) - Convert.ToDouble(dtsource.Rows[j][k]);
                    temp = temp * temp;
                    sum = sum + temp;
                }

                temp1 = Math.Sqrt(sum);
                if (flage && temp1 != 0)
                {
                    smallval = temp1;
                    flage = false;
                }
                if (temp1 != 0 && smallval > temp1 && !flage)
                {
                    smallval = temp1;
                }
                sum = 0;

                dt.Rows[i][j] = temp1;

            }
        }
    }
}

Out put of my code i have given in attachfiles now i need to merge points (0,1) as single point and in the second step (2,3) as single point. From the new point again i need to calculate Distance.

Sir, Please Kindly help me out that how i can merge two datapoints as single point.