Example #1
0
		public virtual int Add(object value)
		{
			if (internalhead == null)
			{
				internalhead = new LinkNode(value);

				internaltail = internalhead;
			}
			else
			{
				// Added this code because internaltail seems to be null in come cases
				if (internaltail == null)
				{
					internaltail = internalhead;

					while(internaltail.Next != null)
						internaltail = internaltail.Next;
				}

				internaltail.Next = new LinkNode(value, null, internaltail);

				internaltail = internaltail.Next;
			}

			return internalcount++;
		}
Example #2
0
		public virtual void AddFirst(object value)
		{
			if (internalhead == null)
			{
				internalhead = new LinkNode(value);
			}
			else
			{
				internalhead = new LinkNode(value, internalhead, null);
			}

			internalcount++;
		}
Example #3
0
		public virtual int AddLast(object value)
		{
			if (internalhead == null)
			{
				internalhead = new LinkNode(value);
			}
			else
			{
				LinkNode p, q;
				for(p = internalhead; (q = p.Next) != null; p = q) ;
				p.Next = new LinkNode(value, null, p);
			}

			return internalcount++;
		}
Example #4
0
		public void Reset()
		{
			_current = internalhead;
			_isFirst = true;
		}
Example #5
0
		public bool MoveNext()
		{
			if (_current == null) return false;

			if (!_isFirst)
			{
				_current = _current.Next;
			}
			else
			{
				_isFirst = false;
			}

			return _current != null;
		}
Example #6
0
		public LinkNode(object value, LinkNode next, LinkNode prev)
		{
			_value = value;
			_next = next;
			_prev = prev;
		}
Example #7
0
		public LinkedListEnumerator(LinkNode node)
		{
			internalhead = node;
			Reset();
		}
Example #8
0
		public virtual void Remove(object value)
		{
			if (internalhead != null)
			{
				if (internalhead.Value.Equals(value))
				{
					if (internalhead == internaltail) internaltail = null;

					internalhead = internalhead.Next;

					internalcount--;
				}
				else if (internaltail.Value.Equals(value))
				{
					internaltail.Previous.Next = null;
					internaltail = internaltail.Previous;

					internalcount--;
				}
				else
				{
					LinkNode node = internalhead.Next;

					while(node != null)
					{
						if (node.Value.Equals(value))
						{
							node.Previous.Next = node.Next;
							node.Next.Previous = node.Previous;
							internalcount--;
							break;
						}

						node = node.Next;
					}
				}
			}
		}
Example #9
0
		public virtual void Insert(int index, object value)
		{
			if (index == 0)
			{
				AddFirst(value);
			}
			else if (index == internalcount)
			{
				AddLast(value);
			}
			else
			{
				LinkNode insert = GetNode(index);
				LinkNode node = new LinkNode(value, insert, insert.Previous);
				insert.Previous.Next = node;
				insert.Previous = node;
				internalcount++;
			}
		}
Example #10
0
		public void Clear()
		{
			internalhead = internaltail = null;
			internalcount = 0;
		}
Example #11
0
		public bool MoveNext()
		{
			if (current == null) return false;

			if (!isFirst)
			{
				current = current.Next;
			}
			else
			{
				isFirst = false;
			}

			return current != null;
		}
Example #12
0
		public LinkNode(object value, LinkNode next, LinkNode previous)
		{
			this.value = value;
			this.next = next;
			this.previous = previous;
		}