예제 #1
0
파일: FileWork.cs 프로젝트: kram161/C-graf
        public GraphStr Read()
        {
            FileStream   stream = new FileStream(FileName, FileMode.Open);
            BinaryReader reader = new BinaryReader(stream);
            GraphStr     graph  = new GraphStr();
            int          Count  = reader.ReadInt32();

            for (int i = 0; i < Count; i++)
            {
                string s = ReadString(reader);
                int    X = reader.ReadInt32();
                int    Y = reader.ReadInt32();
                graph.AddNode(s, X, Y);
            }
            for (int i = 0; i < Count; i++)
            {
                for (int j = i + 1; j < Count; j++)
                {
                    if (reader.ReadBoolean())
                    {
                        int value = reader.ReadInt32();
                        graph.Nodes[i].AddEdge(graph.Nodes[j], value);
                    }
                }
            }
            reader.Close();
            stream.Close();
            return(graph);
        }
예제 #2
0
파일: FileWork.cs 프로젝트: kram161/C-graf
        public void Write(GraphStr graph)
        {
            FileStream   stream = new FileStream(FileName, FileMode.Create);
            BinaryWriter writer = new BinaryWriter(stream);
            int          Count  = graph.Nodes.Count;

            writer.Write(Count);
            List <Node> nodes = graph.Nodes;

            foreach (Node item in nodes)
            {
                WriteString(item.Value, writer);
                writer.Write(item.X);
                writer.Write(item.Y);
            }
            for (int i = 0; i < Count; i++)
            {
                for (int j = i + 1; j < Count; j++)
                {
                    bool t = true;
                    foreach (Edge item in nodes[i].Edges)
                    {
                        if (item.B == nodes[j])
                        {
                            writer.Write(true);
                            writer.Write(item.Value);
                            t = false;
                            break;
                        }
                    }
                    if (t)
                    {
                        writer.Write(false);
                    }
                }
            }
            writer.Close();
            stream.Close();
        }