//read weighted edgelist from the file named input
        public static Helper.edgelist readEdgeList(string input)
        {
            int      s  = NLINKS;
            edgelist el = new edgelist();

            el.edges = new edge[s];
            el.n     = 0;
            el.e     = 0;

            string l = "";

            try
            {
                using (StreamReader sr = new StreamReader(input))
                {
                    while ((l = sr.ReadLine()) != null)
                    {
                        var lineParts = l.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

                        if (lineParts.Length == 3)
                        {
                            el.edges[el.e]   = new edge();
                            el.edges[el.e].u = uint.Parse(lineParts[0]);
                            el.edges[el.e].v = uint.Parse(lineParts[1]);
                            el.edges[el.e].w = double.Parse(lineParts[2]);

                            var wd = new List <uint>();
                            wd.Add(el.n);
                            wd.Add(el.edges[el.e].u);
                            wd.Add(el.edges[el.e].v);
                            wd.Sort();
                            wd.Reverse();
                            el.n = wd[0];

                            if (el.e++ == s)
                            {
                                s += NLINKS;
                                Array.Resize(ref el.edges, s);
                            }
                        }
                    }
                }

                el.n++;
                Array.Resize(ref el.edges, s);
                return(el);
            }

            catch (Exception e)
            {
                Console.WriteLine("Exception: " + e.Message);
                return(el);
            }
        }
 //prepare Vertex List
 public static void prepareVertexList(edgelist el, List <int> vertices)
 {
     try
     {
         int i = 0;
         for (i = 0; i < el.e; i++)
         {
             bool Contains = vertices.Contains((int)el.edges[i].u);
             if (!Contains)
             {
                 vertices.Add((int)el.edges[i].u);
             }
             Contains = vertices.Contains((int)el.edges[i].v);
             if (!Contains)
             {
                 vertices.Add((int)el.edges[i].v);
             }
         }
     }
     catch (Exception e)
     {
         Console.WriteLine("Exception: " + e.Message);
     }
 }
        //prepare weighted vertex list by sum of weights in descending order
        public static vertexDeg[] prepareWeightedVertexList(edgelist el)
        {
            uint i;
            uint j;

            vertexDeg[] nd = new vertexDeg[el.n];   //weighted vertex list storing start vertices for DFS

            try
            {
                //Ordering nodes in non-increasing order of degree
                for (i = 0; i < el.n; i++)
                {
                    nd[i]   = new vertexDeg();
                    nd[i].n = i;
                    nd[i].w = 0;
                }

                //calculate sum of weights for connected nodes
                for (i = 0; i < el.e; i++)
                {
                    nd[el.edges[i].u].w = nd[el.edges[i].u].w + el.edges[i].w;
                    nd[el.edges[i].v].w = nd[el.edges[i].v].w + el.edges[i].w;
                }

                //sort by descending order
                Array.Sort(nd, Helper.compare_vertexDeg);

                return(nd);
            }

            catch (Exception e)
            {
                Console.WriteLine("Exception: " + e.Message);
                return(nd);
            }
        }
        //returns the index from the edge list for given u and v
        public static int FindAnEdgeinEdgeList(edgelist el, int u, int v)
        {
            int i = 0;

            try
            {
                for (i = 0; i < el.e; i++)
                {
                    //returns the index for found egdes
                    if (el.edges[i].u == u && el.edges[i].v == v)
                    {
                        break;
                    }
                }
                return(i);
            }


            catch (Exception e)
            {
                Console.WriteLine("Exception: " + e.Message);
                return(i);
            }
        }