public BinNode FindByValue(string data)
        {
            if (root == null)
            {
                return(null);
            }
            BinNode temp = root;

            while (temp != null)
            {
                if (string.Compare(data, temp.data.get_rollno()) == 0)
                {
                    return(temp);
                }
                if (string.Compare(data, temp.data.get_rollno()) == 1)
                {
                    temp = temp.right;
                }
                else
                {
                    temp = temp.left;
                }
            }
            return(null);
        }
 public void preorder(BinNode root)
 {
     MessageBox.Show(root.data.get_rollno());
     if (root.left != null)
     {
         preorder(root.left);
     }
     if (root.right != null)
     {
         preorder(root.right);
     }
 }
        //normal insertion method (inserts T data into a bst instance)
        public void Insert(Student data)
        {
            if (root == null)
            {
                root = new BinNode(data);
            }

            BinNode current = root;

            while (current != null)
            {
                if (string.Compare(data.get_rollno(), current.data.get_rollno()) == 1)
                {
                    if (current.right != null)
                    {
                        current = current.right;
                        continue;
                    }
                    current.right = new BinNode(data);
                }

                else if (string.Compare(data.get_rollno(), current.data.get_rollno()) == -1)
                {
                    if (current.left != null)
                    {
                        current = current.left;
                        continue;
                    }
                    current.left = new BinNode(data);
                }

                else
                {
                    return;
                }
            }
        }
        private void attendanceBtn_Click(object sender, EventArgs e)
        {
            if (courseBox.Text == "Subject")
            {
                MessageBox.Show("All entries must be filled");
            }
            else if (cameraBtn.Text == "Camera: Off")
            {
                MessageBox.Show("Can not mark attendance. Please open camera");
            }
            else if (String.IsNullOrEmpty(name))
            {
                MessageBox.Show("Can not mark attendance. Person not recognized");
            }
            else
            {
                BinarySearchTree bst = new BinarySearchTree();
                for (ListNode <Student> temp = student_list.getHead(); temp != null; temp = temp.next)
                {
                    bst.Insert(temp.val);
                }
                BinNode bstnode = bst.FindByValue(name);
                std = bstnode.data;
                for (ListNode <Course> temp = std.studentcourses.getHead(); temp != null; temp = temp.next)
                {
                    if (temp.val.get_String().Equals(courseBox.Text))
                    {
                        flag = 1;
                    }
                }
                if (flag == 0)
                {
                    MessageBox.Show("Can not mark.student not registerted");
                    return;
                }
                string attendance_file = courseBox.Text + " " + DateTime.Now.ToString("d-M-yyyy") + ".xls";
                if (File.Exists(attendance_file))
                {
                    // open xls file
                    Workbook  book  = Workbook.Load(attendance_file);
                    Worksheet sheet = book.Worksheets[0];

                    // traverse rows by Index
                    for (int rowIndex = sheet.Cells.FirstRowIndex; rowIndex <= sheet.Cells.LastRowIndex; rowIndex++)
                    {
                        Row row = sheet.Cells.GetRow(rowIndex);
                        if (row.GetCell(0).ToString().Equals(name))
                        {
                            row.SetCell(2, new Cell("Present"));
                        }
                        for (int colIndex = row.FirstColIndex; colIndex <= row.LastColIndex; colIndex++)
                        {
                            Cell cell = row.GetCell(colIndex);
                        }
                    }

                    book.Save(attendance_file);
                }
                else
                {
                    //create new xls file
                    Workbook  workbook  = new Workbook();
                    Worksheet worksheet = new Worksheet("First Sheet");
                    worksheet.Cells.ColumnWidth[0, 0] = 6000;
                    worksheet.Cells.ColumnWidth[0, 1] = 6000;
                    worksheet.Cells.ColumnWidth[0, 2] = 6000;
                    worksheet.Cells[0, 0]             = new Cell("Roll Number");
                    worksheet.Cells[0, 1]             = new Cell("Name");
                    worksheet.Cells[0, 2]             = new Cell("Attendance");
                    for (ListNode <Student> temp = student_list.getHead(); temp != null; temp = temp.next)
                    {
                        for (ListNode <Course> temp1 = temp.val.studentcourses.getHead(); temp1 != null; temp1 = temp1.next)
                        {
                            if (temp1.val.get_String().Equals(courseBox.Text))
                            {
                                if (name.Equals(temp.val.get_rollno()))
                                {
                                    int r = worksheet.Cells.LastRowIndex;
                                    worksheet.Cells[r + 1, 0] = new Cell(temp.val.get_rollno());
                                    worksheet.Cells[r + 1, 1] = new Cell(temp.val.get_name());
                                    worksheet.Cells[r + 1, 2] = new Cell("Present");
                                }
                                else
                                {
                                    int r = worksheet.Cells.LastRowIndex;
                                    worksheet.Cells[r + 1, 0] = new Cell(temp.val.get_rollno());
                                    worksheet.Cells[r + 1, 1] = new Cell(temp.val.get_name());
                                    worksheet.Cells[r + 1, 2] = new Cell("Absent");
                                }
                            }
                        }
                    }
                    workbook.Worksheets.Add(worksheet);
                    workbook.Save(attendance_file);
                }
                MessageBox.Show("Attendance Marked Successfully");
                this.Hide();
                this.Close();
                Form1 form1 = new Form1();
                form1.ShowDialog();
                // traverse cells
                //foreach (Pair, Cell > cell in sheet.Cells)
                //{
                //    dgvCells[cell.Left.Right, cell.Left.Left].Value = cell.Right.Value;
                //}
            }
        }