本文整理汇总了C#中SinglyLinkedLists.SinglyLinkedList.Count方法的典型用法代码示例。如果您正苦于以下问题:C# SinglyLinkedList.Count方法的具体用法?C# SinglyLinkedList.Count怎么用?C# SinglyLinkedList.Count使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SinglyLinkedLists.SinglyLinkedList
的用法示例。
在下文中一共展示了SinglyLinkedList.Count方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SinglyLinkedList
// READ: http://msdn.microsoft.com/en-us/library/6x16t2tx.aspx
// list [i] = value; i is new list q is old list
public string this[int i]
{
get { return this.ElementAt(i); }
set {
var placeHolderList = new SinglyLinkedList();
for (var q = 0; q < this.Count(); q++)
{
if (q==i)
{
placeHolderList.AddLast(value);
}
else
{
placeHolderList.AddLast(this.ElementAt(q));
}
}
first_node = new SinglyLinkedListNode(placeHolderList.First());
for (var w = 1; w < placeHolderList.Count(); w++)
{
this.AddLast(placeHolderList.ElementAt(w));
}
}
}
示例2: SinglyLinkedList
// READ: http://msdn.microsoft.com/en-us/library/6x16t2tx.aspx
public string this[int i]
{
//uses the ElementAt function to get value (saves you from duplicating your code)
get { return this.ElementAt(i); }
set
{
//using a placeholder list helps save the values in order without having to do voodoo with the pointers
var placeholderList = new SinglyLinkedList();
for (var q = 0; q < this.Count(); q++)
{
//if this is the place where you need to exchange the value, insert it here
if (q == i)
{
placeholderList.AddLast(value);
}
//otherwise, insert the value that was preexisting in the list
else
{
placeholderList.AddLast(this.ElementAt(q));
}
}
//now swap out the values in the placeholder list into the real list.
//first swap the first value to clear out the old list
first_node = new SinglyLinkedListNode(placeholderList.First());
//then loop through the placeholder list and add the values to the real list in order
for (var w = 1; w < placeholderList.Count(); w++)
{
this.AddLast(placeholderList.ElementAt(w));
}
}
}
示例3: SinglyLinkedList
// READ: http://msdn.microsoft.com/en-us/library/6x16t2tx.aspx
public string this[int i]
{
get { return this.ElementAt(i); }
set
{
var copy_of_list = new SinglyLinkedList();
for (var j = 0; j < this.Count(); j++)
{
if (j == i)
{
copy_of_list.AddLast(value);
}
else
{
copy_of_list.AddLast(this.ElementAt(j));
}
}
first_node = new SinglyLinkedListNode(copy_of_list.First());
for (var o = 1; o < copy_of_list.Count(); o++)
{
this.AddLast(copy_of_list.ElementAt(o));
}
}
}
示例4: SinglyLinkedList
// READ: http://msdn.microsoft.com/en-us/library/6x16t2tx.aspx
public string this[int index]
{
get
{
return this.ElementAt(index);
}
set
{
var placeholder = new SinglyLinkedList();
for(var j = 0; j < this.Count(); j++)
{
if (j == index)
{
placeholder.AddLast(value);
} else
{
placeholder.AddLast(this.ElementAt(j));
}
}
first_node = new SinglyLinkedListNode(placeholder.First());
for(var k = 1; k < placeholder.Count(); k++ )
{
this.AddLast(placeholder.ElementAt(k));
}
}
}
示例5: SinglyLinkedList
// READ: http://msdn.microsoft.com/en-us/library/6x16t2tx.aspx
public string this[int i]
{
get { return this.ElementAt(i); }
set
{
var newList = new SinglyLinkedList();
for (var x = 0; x < this.Count(); x++)
{
if (x == i)
{
newList.AddLast(value);
}
else
{
newList.AddLast(this.ElementAt(x));
}
}
first_node = new SinglyLinkedListNode(newList.First());
for (var w = 1; w < newList.Count(); w++)
{
this.AddLast(newList.ElementAt(w));
}
}
}
示例6: SinglyLinkedList
// READ: http://msdn.microsoft.com/en-us/library/6x16t2tx.aspx
public string this[int i]
{
get {return this.ElementAt(i); }
set
{
var placeholder = new SinglyLinkedList();
for (var k = 0; k < this.Count(); k++)
{
if (i == k)
{
placeholder.AddLast(value); //if this is the position this is the new value and don't save the existing value.
}else
{
placeholder.AddLast(this.ElementAt(k));
}
}
first_node = new SinglyLinkedListNode(placeholder.First());//assign first node to be the new list
for (var j = 1; j < placeholder.Count(); j++)
{
this.AddLast(placeholder.ElementAt(j));//add the remaining values in list
}
}
}
示例7: AddAfter
public void AddAfter(string existingValue, string value)
{
//Create an int to store the place in line of the newValue
int testForValue = -1;
//find the existing value in the linked list and assign the place in testForValue
for (var i = 0; i < this.Count(); i++)
{
if (this.ElementAt(i) == existingValue)
{
testForValue = i;
break;
}
}
//if the existing value isn't in the linked list (if it remains a -1 after the if statement), throw an error
if (testForValue < 0)
{
throw new ArgumentException();
}
//use a placeholder linked list to store the nodes in the correct order
var placeholderList = new SinglyLinkedList();
//loop through the current linked list and assign each of the values to the placeholder list
//and insert the new value in its proper place
for (var q = 0; q < this.Count(); q++)
{
//add each value to the placeholder list
placeholderList.AddLast(this.ElementAt(q));
//if this spot is the spot where you need to add the new value, add the new value here
if (q == testForValue)
{
placeholderList.AddLast(value);
}
}
//now reassign the values to the current linked list in order (this.First() etc)
first_node = new SinglyLinkedListNode(placeholderList.First());
for (var w = 1; w < placeholderList.Count(); w++)
{
this.AddLast(placeholderList.ElementAt(w));
}
}
示例8: Remove
public void Remove(string value)
{
int indexValue = this.IndexOf(value);
var placeholder = new SinglyLinkedList();
for(var i = 0; i < this.Count(); i++)
{
if(i != indexValue )
{
placeholder.AddLast(this.ElementAt(i));
}
}
first_node = new SinglyLinkedListNode(placeholder.First());
for (var j = 1; j < placeholder.Count(); ++j)
{
this.AddLast(placeholder.ElementAt(j));
}
}
示例9: CountChangesOnRemoval
public void CountChangesOnRemoval()
{
SinglyLinkedList list = new SinglyLinkedList("foo", "bar", "grille");
list.Remove("foo");
Assert.AreEqual(2, list.Count());
list.Remove("bar");
Assert.AreEqual(1, list.Count());
list.Remove("grille");
Assert.AreEqual(0, list.Count());
}
示例10: CountNItemList
public void CountNItemList()
{
SinglyLinkedList list = new SinglyLinkedList();
list.AddLast("foo");
list.AddLast("bar");
list.AddLast("grille");
list.AddLast("baz");
Assert.AreEqual(4, list.Count());
}
示例11: Remove
public void Remove(string value)
{
int position = IndexOf(value);
var placeholder = new SinglyLinkedList();
for (var i = 0; i < this.Count(); i++)
{
if (i != position)
{
placeholder.AddLast(ElementAt(i));
}
}
first_node = new SinglyLinkedListNode(placeholder.First());//assign first node to be the new list
for (var j = 1; j < placeholder.Count(); j++)
{
this.AddLast(placeholder.ElementAt(j));//add the remaining values in list
}
}
示例12: SinglyLinkedList
// READ: http://msdn.microsoft.com/en-us/library/6x16t2tx.aspx
public string this[int i]
{
get
{
return this.ElementAt(i);
}
set
{
var copy_of_list = new SinglyLinkedList();
for (var k = 0; k < this.Count(); k++)
{
if (k == i)
{
copy_of_list.AddLast(value);
}
else
{
copy_of_list.AddLast(this.ElementAt(k));
}
}
first_node = new SinglyLinkedListNode(copy_of_list.First());
for (var Y = 1; Y < copy_of_list.Count(); Y++)
{
this.AddLast(copy_of_list.ElementAt(Y));
}
}
}
示例13: TestingMyCountMethodForNewList
public void TestingMyCountMethodForNewList()
{
SinglyLinkedList list = new SinglyLinkedList();
int expected = 0;
Assert.AreEqual(expected, list.Count());
}
示例14: AddAfter
public void AddAfter(string existingValue, string newValue)
{
int testForValue = -1;
//throw new NotImplementedException();
for (var i = 0; i < this.Count(); i++)
{
if (this.ElementAt(i) == existingValue)
{
testForValue = i;
break;
}
}
if (testForValue < 0)
{
throw new ArgumentException();
}
var placeHolderList = new SinglyLinkedList();
for (var q = 0; q < this.Count(); q++)
{
placeHolderList.AddLast(this.ElementAt(q));
if (q == testForValue)
{
placeHolderList.AddLast(newValue);
}
}
first_node = new SinglyLinkedListNode(placeHolderList.First());
for (var w = 1; w < placeHolderList.Count(); w++)
{
this.AddLast(placeHolderList.ElementAt(w));
}
}
示例15: AddFirst
public void AddFirst(string value)
{
if (this.First() == null)
{
first_node = new SinglyLinkedListNode(value);
}
else
{
var newFirstNode = new SinglyLinkedListNode(value);
var placeHolderList = new SinglyLinkedList();
placeHolderList.AddFirst(newFirstNode.Value);
for (var i = 0; i < this.Count(); i++)
{
placeHolderList.AddLast(this.ElementAt(i));
}
first_node = new SinglyLinkedListNode(placeHolderList.First());
for (var q = 1; q < placeHolderList.Count(); q++)
{
this.AddLast(placeHolderList.ElementAt(q));
}
}
}