List.isEmpty与List.size() > 0

        List<String> list = new ArrayList<String>();

        System.out.println("list.isEmpty():" + list.isEmpty());
        System.out.println("list.size() > 0:" + (list.size() > 0));

        list.add(null);
        System.out.println("加入null 对象list.isEmpty():" + list.isEmpty());
        System.out.println("加入null 对象list.size() > 0:" + (list.size() > 0));
//      list.isEmpty():true
//      list.size() > 0:false
//      加入null 对象list.isEmpty():false
//      加入null 对象list.size() > 0:true
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
线性表C++语言实现,包含《数据结构算法与应用-C++语言描述》练习题。 template<class T> class LinearList { public: LinearList(int MaxListSize = 10);//构造函数 LinearList(LinearList<T>& L);//复制构造函数 ~LinearList() { delete[] element; }//析构函数 bool IsEmpty() const { return length == 0; }//判断线性表是否为空 int Length() const { return length; }//返回数组长度 void SetLength(int SetLength) { length = SetLength; }//设置数组长度 int MaxSize_ret() const { return MaxSize; }//返回数组最大长度 int Current_ret(void) const { return current; } bool Find(int k, T& x);//返回第k个元素至x中 int Search(const T& x) const;//返回x所在位置 LinearList<T>& Delete(int k, T& x);//删除第k个元素并将它返回至x中 LinearList<T>& Insert(int k, const T& x);//在第k个元素之后插入x LinearList<T>& Insert(const T& x);//在表尾插入x void Output(ostream& out) const; void Self_adaption_LinearList_Size(void); void Reverse(void); bool Half(void); LinearList<T>& Alternate(LinearList<T>& A, LinearList<T>& B); LinearList<T>& Merge(LinearList<T>& A, LinearList<T>& B); LinearList<T>& Merge_1(LinearList<T>& A, LinearList<T>& B); void Split(LinearList<T>& A, LinearList<T>& B); LinearList<T>& Sort(void); /*关于前移和后移*/ void Reset(void) { current = 1; } //置current为0 T Current(void) { return element[current-1]; }//返回当前元素 bool End(void);//当且仅当当前元素为表的最后一个元素时,返回true bool Front(void);//当且仅当当前元素为表的第一个元素时,返回true void Next(void);//移动current至表中的下一个元素,如果操作失败则引发一个异常 void Previous(void);//移动current至表中的前一个元素,如果操作失败则引发一个异常 private: int length;//线性表长度 int MaxSize;//线性表最大可容纳的长度 int current;//记录线性表当前的位置 T* element;//一维动态数组 };

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值