⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 list

📁 C语言库函数的原型,有用的拿去
💻
📖 第 1 页 / 共 4 页
字号:
				::IsReadOnly::get
			{	// test if read only
			return (false);
			}
		};

	virtual void CopyTo(_Myarray_t^ _Dest, int _First) sealed
		= System::Collections::Generic::ICollection<_Value_t>::CopyTo
		{	// copy to _Dest, beginning at _First
		node_type^ _Node = head_node();

		for (int _Idx = size(); 0 <= --_Idx; )
			{	// copy back to front
			_Node = _Node->prev_node();
			_Dest[_First + _Idx] = _Mymake_t::make_value(_Node->_Myval);
			}
		}

	virtual System::Collections::Generic::IEnumerator<_Value_t>^
		GetEnumerator() sealed
		= System::Collections::Generic::IEnumerable<_Value_t>::GetEnumerator
		{	// get enumerator for the container
		return (gcnew _STLCLR ListEnumerator<_Value_t>(front_node()));
		}

	virtual void Add(value_type _Val) sealed
		= System::Collections::Generic::ICollection<_Value_t>::Add
		{	// add element with value _Val
		insert_node(head_node(), 1, _Val);
		}

	virtual void Clear() sealed
		= System::Collections::Generic::ICollection<_Value_t>::Clear
		{	// erase all elements
		clear();
		}

	virtual bool Contains(value_type _Val) sealed
		= System::Collections::Generic::ICollection<_Value_t>::Contains
		{	// search for element matching value _Val
		for (node_type^ _Node = front_node(); _Node != head_node();
			_Node = _Node->next_node())
			if (((System::Object^)_Val)->Equals(
				(System::Object^)_Node->_Myval))
				return (true);
		return (false);
		}

	virtual bool Remove(value_type _Val) sealed
		= System::Collections::Generic::ICollection<_Value_t>::Remove
		{	// remove first element matching value _Val
		for (node_type^ _Node = front_node(); _Node != head_node();
			_Node = _Node->next_node())
			if (((System::Object^)_Val)->Equals(
				(System::Object^)_Node->_Myval))
				{	// found a match, remove it
				erase_node(_Node);
				return (true);
				}
		return (false);
		}
	};

//
// TEMPLATE CLASS list_select
//
template<typename _Value_t,
	bool _Is_ref>
	ref class list_select
	:	public list_base<_Value_t, _Is_ref>
	{	// bidirectional linked list of elements
public:
	// types
	typedef _Value_t _Gvalue_t;

	typedef list_select<_Value_t, _Is_ref> _Mytype_t;
	typedef list_base<_Gvalue_t, _Is_ref> _Mybase_t;
//	typedef _STLCLR IList<_Gvalue_t> _Mycont_it;
//	typedef System::Collections::Generic::IEnumerable<_Gvalue_t> _Myenum_it;

//	typedef int size_type;
//	typedef int difference_type;
	typedef _Value_t value_type;
	typedef value_type% reference;
	typedef value_type% const_reference;

//	typedef _Mycont_it generic_container;
//	typedef typename _Mybase_t::value_type generic_value;

	// basics
	list_select()
		:	_Mybase_t()
		{	// construct default
		}

	list_select(list_select% _Right)
		:	_Mybase_t(_Right)
		{	// construct by copying a list
		}

	list_select% operator=(list_select% _Right)
		{	// assign
		_Mybase_t::operator=(_Right);
		return (*this);
		}

	// constructors
	explicit list_select(size_type _Count)
		:	_Mybase_t(_Count)
		{	// construct from _Count * value_type()
		}

	list_select(size_type _Count, value_type _Val)
		:	_Mybase_t(_Count, _Val)
		{	// construct from _Count * _Val
		}

	template<typename _InIt_t>
		list_select(_InIt_t _First, _InIt_t _Last)
		:	_Mybase_t(_First, _Last)
		{	// construct from [_First, _Last)
		}

	list_select(_Myenum_it^ _Right)
		:	_Mybase_t(_Right)
		{	// initialize with enumeration
		}
	};

//
// TEMPLATE CLASS list_select: _Value_t REF SPECIALIZATION
//
template<typename _Value_t>
	ref class list_select<_Value_t, true>
	:	public list_base<_Value_t^, true>
	{	// bidirectional linked list of elements
public:
	// types
	typedef _Value_t^ _Gvalue_t;

	typedef list_select<_Value_t, true> _Mytype_t;
	typedef list_base<_Gvalue_t, true> _Mybase_t;
//	typedef _STLCLR IList<_Gvalue_t> _Mycont_it;
//	typedef System::Collections::Generic::IEnumerable<_Gvalue_t> _Myenum_it;

//	typedef int size_type;
//	typedef int difference_type;
	typedef _Value_t value_type;
	typedef value_type% reference;
	typedef value_type% const_reference;

//	typedef _Mycont_it generic_container;
//	typedef typename _Mybase_t::value_type generic_value;

	// basics
	list_select()
		:	_Mybase_t()
		{	// construct default
		}

	list_select(list_select% _Right)
		:	_Mybase_t(_Right)
		{	// construct by copying a list
		}

	list_select% operator=(list_select% _Right)
		{	// assign
		_Mybase_t::operator=(_Right);
		return (*this);
		}

	// constructors
	explicit list_select(size_type _Count)
		{	// construct from _Count * value_type()
		resize(_Count);
		}

	list_select(size_type _Count, value_type _Val)
		{	// construct from _Count * _Val
		resize(_Count, _Val);
		}

	template<typename _InIt_t>
		list_select(_InIt_t _First, _InIt_t _Last)
		:	_Mybase_t(_First, _Last)
		{	// construct from [_First, _Last)
		}

	list_select(_Myenum_it^ _Right)
		:	_Mybase_t(_Right)
		{	// initialize with enumeration
		}

	// size controllers
	virtual void resize(size_type _Newsize) override
		{	// determine new length, padding with value_type elements
		value_type _Val;

		_Mybase_t::resize(_Newsize, %_Val);
		}

	void resize(size_type _Newsize, value_type _Val) 
		{	// determine new length, padding with _Val elements
		_Mybase_t::resize(_Newsize, %_Val);
		}

	// accessors
	property value_type front_item
		{	// get or set first element
		virtual value_type get()
			{	// get first element
			return (*_Mybase_t::front_item);
			}

		virtual void set(value_type _Val)
			{	// set first element
			_Mybase_t::front_item = gcnew value_type(_Val);
			}
		};

	property value_type back_item
		{	// get or set last element
		virtual value_type get()
			{	// get last element
			return (*_Mybase_t::back_item);
			}

		virtual void set(value_type _Val)
			{	// set last element
			_Mybase_t::back_item = gcnew value_type(_Val);
			}
		};

	reference front() new
		{	// get first element of mutable sequence
		return (*_Mybase_t::front());
		}

	reference back() new
		{	// get last element of mutable sequence
		return (*_Mybase_t::back());
		}

	// mutators
	void push_front(value_type _Val)
		{	// insert element at beginning
		_Mybase_t::push_front(%_Val);
		}

	void push_back(value_type _Val)
		{	// insert element at end
		_Mybase_t::push_back(%_Val);
		}

	void assign(size_type _Count, value_type _Val) 
		{	// assign _Count * _Val
		_Mybase_t::assign(_Count, %_Val);
		}

	iterator insert(iterator _Where, value_type _Val) 
		{	// insert _Val at _Where
		return (_Mybase_t::insert(_Where, %_Val));
		}

	void insert(iterator _Where,
		size_type _Count, value_type _Val) 
		{	// insert _Count * _Val at _Where
		return (_Mybase_t::insert(_Where, _Count, %_Val));
		}

	// special functions
	void remove(value_type _Val)
		{	// erase each element matching _Val
		_Mybase_t::remove(%_Val);
		}
	};
	}	// namespace cliext::impl

//
// TEMPLATE REF CLASS list
//
template<typename _Value_t>
	ref class list
	:	public impl::list_select<
		_Value_t,
		__is_ref_class(typename _Dehandle<_Value_t>::type)
			&& !is_handle<_Value_t>::value>
	{	// bidirectional linked list of elements
public:
	// types
	typedef list<_Value_t> _Mytype_t;
	typedef impl::list_select<_Value_t,
		__is_ref_class(typename _Dehandle<_Value_t>::type)
		&& !is_handle<_Value_t>::value> _Mybase_t;
//	typedef impl::_STLCLR IList<_Value_t> _Mycont_it;

//	typedef int size_type;
//	typedef int difference_type;
//	typedef _Value_t value_type;
//	typedef value_type% reference;
//	typedef value_type% const_reference;

//	typedef _Mycont_it generic_container;
//	typedef value_type generic_value;

	// basics
	list()
		:	_Mybase_t()
		{	// construct default
		}

	list(list% _Right)
		:	_Mybase_t((_Mybase_t%)_Right)
		{	// construct by copying a list
		}

	list(list^ _Right)
		:	_Mybase_t((_Mybase_t%)*_Right)
		{	// construct by copying a list
		}

	list% operator=(list% _Right)
		{	// assign
		_Mybase_t::operator=(_Right);
		return (*this);
		}

	list% operator=(list^ _Right)
		{	// assign
		_Mybase_t::operator=(*_Right);
		return (*this);
		}

	// constructors
	explicit list(size_type _Count)
		:	_Mybase_t(_Count)
		{	// construct from _Count * value_type()
		}

	list(size_type _Count, value_type _Val)
		:	_Mybase_t(_Count, _Val)
		{	// construct from _Count * _Val
		}

	template<typename _InIt_t>
		list(_InIt_t _First, _InIt_t _Last)
		:	_Mybase_t(_First, _Last)
		{	// construct from [_First, _Last)
		}

	list(_Myenum_it^ _Right)
		:	_Mybase_t(_Right)
		{	// initialize with enumeration
		}

	// converters
	virtual System::Object^ Clone() override
		{	// clone the vector
		return (gcnew _Mytype_t(*this));
		}

	// mutators
	void swap(list% _Right)
		{	// exchange contents with _Right
		_Mybase_t::swap(_Right);
		}
	};

//
// TEMPLATE COMPARISONS
//
template<typename _Value_t> inline
	bool operator==(list<_Value_t>% _Left,
		list<_Value_t>% _Right)
	{	// test if _Left == _Right
	typedef list<_Value_t> _Mytype_t;

	_Mytype_t::size_type _Size = _Left.size();

	if (_Size != _Right.size())
		return (false);
	else
		{	// same length, compare elements
		_Mytype_t::node_type^ _Pleft = _Left.front_node();
		_Mytype_t::node_type^ _Pright = _Right.front_node();

		for (; 0 < _Size; --_Size)
			{	// compare next two elements
			if (_Pleft->_Myval != _Pright->_Myval)
				return (false);
			_Pleft = _Pleft->_Next;
			_Pright = _Pright->_Next;
			}
		return (true);
		}
	}

template<typename _Value_t> inline
	bool operator!=(list<_Value_t>% _Left,
		list<_Value_t>% _Right)
	{	// test if _Left != _Right
	return (!(_Left == _Right));
	}

template<typename _Value_t> inline
	bool operator<(list<_Value_t>% _Left,
		list<_Value_t>% _Right)
	{	// test if _Left < _Right
	typedef list<_Value_t> _Mytype_t;

	_Mytype_t::size_type _Idx = 0;
	_Mytype_t::node_type^ _Pleft = _Left.front_node();
	_Mytype_t::node_type^ _Pright = _Right.front_node();

	for (; _Idx != _Left.size() && _Idx != _Right.size(); ++_Idx)
		{	// compare next two elements
		if (_Pleft->_Myval < _Pright->_Myval)
			return (true);
		else if (_Pright->_Myval < _Pleft->_Myval)
			return (false);
		_Pleft = _Pleft->_Next;
		_Pright = _Pright->_Next;
		}
	return (_Idx == _Left.size() && _Idx != _Right.size());
	}

template<typename _Value_t> inline
	bool operator>=(list<_Value_t>% _Left,
		list<_Value_t>% _Right)
	{	// test if _Left >= _Right
	return (!(_Left < _Right));
	}

template<typename _Value_t> inline
	bool operator>(list<_Value_t>% _Left,
		list<_Value_t>% _Right)
	{	// test if _Left > _Right
	return (_Right < _Left);
	}

template<typename _Value_t> inline
	bool operator<=(list<_Value_t>% _Left,
		list<_Value_t>% _Right)
	{	// test if _Left <= _Right
	return (!(_Right < _Left));
	}

//
// TEMPLATE FUNCTION swap
//
template<typename _Value_t> inline
	void swap(list<_Value_t>% _Left,
		list<_Value_t>% _Right)
	{	// swap two lists
	_Left.swap(_Right);
	}

}	// namespace cliext
#endif // _CLI_LIST_

/*
 * Copyright (c) 2004-2007 by Dinkumware, Ltd.  ALL RIGHTS RESERVED.
 * Consult your license regarding permissions and restrictions.
V5.03:0009 */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -