Ejemplo n.º 1
0
        /// <summary>
        /// Loads data from file to BinarySearchTree object.
        /// </summary>
        /// <param name="filename">Name of file from which to load data.</param>
        /// <param name="studentsAsBinaryTree">BinarySearchTree object in which to store data.</param>
        internal void LoadStudents(string filename, BinarySearchTree <StudentTestMark> studentsAsBinaryTree)
        {
            if (File.Exists(filename))
            {
                // load all bytes into MemoryStrem
                var memoryFile = new MemoryStream(File.ReadAllBytes(filename));
                // then read them through Binary Reader
                using (var reader = new BinaryReader(memoryFile))
                {
                    while (reader.BaseStream.Position < reader.BaseStream.Length - 1)
                    {
                        var studentAndHisMark = new StudentTestMark
                        {
                            Name       = reader.ReadString(),
                            TestName   = reader.ReadString(),
                            TestDate   = DateTime.FromBinary(reader.ReadInt64()),
                            Assessment = reader.ReadInt32()
                        };

                        studentsAsBinaryTree.Add(studentAndHisMark);
                    }
                }
            }
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Default IComparable method which may be needed for BinarySearchTree creation (in case
 /// a custom Comparison method is not specified in the call of BinarySearchTree constructor)
 /// </summary>
 /// <param name="other">The other object to compare this object to.</param>
 /// <returns>0 = equal, -1 = this is less than the other, 1 = this is higher than the other.</returns>
 public int CompareTo(StudentTestMark other)
 {
     return(this.Assessment.CompareTo(other.Assessment));
 }