我在学习数据结构的过程中,其中有一章的课后习题让把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()更好,但是我想知道改为属性后该怎样实现)
其中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()更好,但是我想知道改为属性后该怎样实现)
{
get
{
if (head == null)
{
return true;
}
else
{
return false;
}
}
}