Exemple #1
0
        public void BuildDegreeList(ref Vertex[] verticies, ref DegreeList degList)
        {
            for (int i = 0; i < AL.Length; i++)
            {
                if (AL[i] == null)
                {
                    continue;
                }

                int       count = 0;
                AdjVertex curr  = AL[i];
                while (curr != null)
                {
                    ++count;
                    curr = curr.next;
                }
                verticies[i].degree = count;
                degList.Insert(verticies[i]);
            }
        }
Exemple #2
0
        public void BuildGraph()
        {
            StreamReader srP = new StreamReader(pathToP);
            StreamReader srE = new StreamReader(pathToE);

            //First line of P tells you the number of courses
            String pLine = srP.ReadLine();

            int.TryParse(pLine, out numCourses);
            //Allocate memory
            adjList   = new AdjList(numCourses + 1);
            degList   = new DegreeList(numCourses + 1);
            verticies = new Vertex[numCourses + 1];
            stack     = new Stack(numCourses + 1);

            pLine = srP.ReadLine();

            //First line of E is always 0 so skip it
            String eLine = srE.ReadLine();

            eLine = srE.ReadLine();

            int courseNumber = 1;
            int extra        = 0;
            int parsed;
            int curr;
            int prev;

            int.TryParse(pLine, out prev);

            while (pLine != null)
            {
                pLine = srP.ReadLine();
                while (pLine == "0")
                {
                    ++extra;
                    pLine = srP.ReadLine();
                }
                if (pLine == null)
                {
                    while (eLine != null)
                    {
                        int.TryParse(eLine, out parsed);

                        AddVertex(parsed, courseNumber);
                        eLine = srE.ReadLine();
                    }
                }
                else
                {
                    int.TryParse(pLine, out curr);
                    int difference = curr - prev;
                    for (int i = 0; i < difference; i++)
                    {
                        int.TryParse(eLine, out parsed);

                        AddVertex(parsed, courseNumber);
                        eLine = srE.ReadLine();
                    }
                    prev         = curr;
                    courseNumber = courseNumber + extra + 1;
                    extra        = 0;
                }
            }

            adjList.BuildDegreeList(ref verticies, ref degList);
            if (verbose)
            {
                adjList.Print();
                degList.Print();
            }
            graphBuilt = true;
        }