我在学习数据结构的过程中,其中有一章的课后习题让把LinkList的IsEmpty()方法改为该类的属性,我不知道怎么样改算法比较好,有没有人帮我指点一下,非常感谢!
  其中Linklist的IsEmpty()方法如下:     public bool IsEmpty()
        {
           if(head == null)
            {
                return true;
            }
            else
            {
                return false;
            }
        }我改为:
(在这个类中声明一个变量  private bool _isEmpty;)
           public bool IsEmpty
        {
            get
            {
                return _isEmpty;
            }
            set
            {
                _isEmpty = value;
            }
        }如果这样的话,在实现这个属性的时候就比较麻烦了,有没有更好的方法。(当然用IsEmpty()更好,但是我想知道改为属性后该怎样实现)

解决方案 »

  1.   

     public bool IsEmpty//这应该是一个只读的属性,故而不实现set访问器
            {
                get
                {
                    if (head == null)
                    {
                        return true;
                    }
                    else
                    {
                        return false;
                    }
                }
            }