本文整理汇总了C#中Queue.IsEmpty方法的典型用法代码示例。如果您正苦于以下问题:C# Queue.IsEmpty方法的具体用法?C# Queue.IsEmpty怎么用?C# Queue.IsEmpty使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Queue
的用法示例。
在下文中一共展示了Queue.IsEmpty方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestQueue
public void TestQueue()
{
var st = new Queue<int>();
for (int i = 0; i < 10; i++)
{
st.EnQueue(i);
}
Assert.AreEqual(st.Top(), 0);
Assert.AreEqual(st.DeQueue(), 0);
Assert.AreEqual(st.Top(), 1);
while (!st.IsEmpty())
st.DeQueue();
try
{
var t = st.Top(); // should raise Exception here
Assert.IsTrue(false);
}
catch (Exception)
{
// should be here
}
}
示例2: Run
public void Run()
{
const string fieName = "tobe.txt";
var @in = new In($"Files\\Collections\\{fieName}");
var words = @in.ReadAllStrings();
var queue = new Queue<string>();
foreach (var word in words)
{
queue.Enqueue(word);
}
Console.WriteLine("size of queue = {0}", queue.Size());
foreach (var item in queue)
{
Console.WriteLine("item = {0}", item);
}
while (!queue.IsEmpty())
{
var item = queue.Dequeue();
Console.WriteLine("item = {0}", item);
}
Console.ReadLine();
}
示例3: GetAllFiles
public static ICollection<FileInfo> GetAllFiles(this DirectoryInfo directoryInfo, string searchPattern)
{
var resultFiles = new List<FileInfo>();
var unprocessedDirectories = new Queue<DirectoryInfo>();
unprocessedDirectories.Enqueue(directoryInfo);
while (!unprocessedDirectories.IsEmpty())
{
var tempDirectoryInfo = unprocessedDirectories.Dequeue();
var directories = tempDirectoryInfo.GetDirectories();
foreach (var directory in directories)
{
if (directory.Attributes.HasFlag(FileAttributes.ReparsePoint))
continue;
unprocessedDirectories.Enqueue(directory);
}
resultFiles.AddRange(tempDirectoryInfo.GetFiles(searchPattern));
}
return resultFiles;
}
示例4: Check
public bool Check(Queue<HtmlNode> referenceQueue)
{
if (referenceQueue == null || referenceQueue.IsEmpty())
{
throw new ArgumentNullException("referenceQueue");
}
if (IsPropertyNode(referenceQueue.Peek()))
{
var node = referenceQueue.Dequeue();
var propertyName = node.InnerText.Substring(MODEL_PREFIX.Length);
currentProperty = new PropertyDTO(propertyName, MODEL_PREFIX + propertyName);
return true;
}
return false;
}
示例5: MapChildren
private MappedHtmlNode[] MapChildren()
{
var children = new List<MappedHtmlNode>();
var htmlChildren = new Queue<HtmlNode>(htmlNode.ChildNodes);
var referenceChildren = new Queue<HtmlNode>(referenceNode.ChildNodes);
var list = new List<HtmlNode>();
while (!htmlChildren.IsEmpty())
{
if (referenceChildren.IsEmpty())
{
if (list.Count > 0)
{
throw new InvalidOperationException("The node passed on as a reference is not a subset of the html node");
}
CreateProperty(htmlChildren.ToList(), children);
break;
}
else if (propertyNameState.Check(referenceChildren))
{
isProperty = true;
continue;
}
var htmlChild = htmlChildren.Dequeue();
if (comparer.Equals(htmlChild, referenceChildren.Peek()))
{
CreateProperty(list, children);
children.Add(new MappedHtmlNodeToReferenceNode(this, htmlChild, referenceChildren.Dequeue(), comparer, propertyNameState));
}
else
{
list.Add(htmlChild);
}
}
if (!referenceChildren.IsEmpty() && propertyNameState.Check(referenceChildren))
{
isProperty = true;
CreateProperty(list, children);
}
return children.ToArray();
}
示例6: Main
public static void Main()
{
try {
Queue q1 = new Queue();
Queue q2 = new Queue(3);
q2.Add(4);
q2.Add(5);
Console.WriteLine("The front is now {0}", q2.Head());
q2.Add(6);
Console.WriteLine
("Removing from q2 returns {0}", q2.Remove());
Console.WriteLine("Queue 1 has size {0}", q1.size);
Console.WriteLine("Queue 1 empty? {0}", q1.IsEmpty());
q1.Remove();
Console.WriteLine("Throws exception before we get here");
}catch(Exception e) {
Console.WriteLine(e);
}
}
示例7: ShortestPath
public static int ShortestPath(Vertex start, Vertex end)
{
Queue<Vertex> queue = new Queue<Vertex>(10);
if (start == null || end == null)
return 0;
start.Status = Color.Grey;
queue.Push(start);
Vertex cur = null;
while (!queue.IsEmpty())
{
cur = queue.Pop();
if (cur == end)
{
break;
}
foreach (Vertex v in cur.Neighbors)
{
if (v.Status == Color.White)
{
v.Status = Color.Grey;
v.Parent = cur;
v.Distance = cur.Distance + 1;
queue.Push(v);
}
}
cur.Status = Color.Black;
}
if (cur.Parent == null)
return 0;
else
return cur.Parent.Distance + 1;
}
示例8: GetTypeParameters
private IList<ITypeParameterSymbol> GetTypeParameters(INamedTypeSymbol type, IEnumerable<ISymbol> includedMembers)
{
var potentialTypeParameters = GetPotentialTypeParameters(type);
var directlyReferencedTypeParameters = GetDirectlyReferencedTypeParameters(potentialTypeParameters, includedMembers);
// The directly referenced TypeParameters may have constraints that reference other
// type parameters.
var allReferencedTypeParameters = new HashSet<ITypeParameterSymbol>(directlyReferencedTypeParameters);
var unanalyzedTypeParameters = new Queue<ITypeParameterSymbol>(directlyReferencedTypeParameters);
while (!unanalyzedTypeParameters.IsEmpty())
{
var typeParameter = unanalyzedTypeParameters.Dequeue();
foreach (var constraint in typeParameter.ConstraintTypes)
{
foreach (var originalTypeParameter in potentialTypeParameters)
{
if (!allReferencedTypeParameters.Contains(originalTypeParameter) &&
DoesTypeReferenceTypeParameter(constraint, originalTypeParameter, new HashSet<ITypeSymbol>()))
{
allReferencedTypeParameters.Add(originalTypeParameter);
unanalyzedTypeParameters.Enqueue(originalTypeParameter);
}
}
}
}
return potentialTypeParameters.Where(p => allReferencedTypeParameters.Contains(p)).ToList();
}
示例9: IsEmpty_NoElements_True
public void IsEmpty_NoElements_True()
{
Queue<object> queue = new Queue<object>();
Assert.AreEqual(true, queue.IsEmpty());
}
示例10: IsEmpty_1add_False
public void IsEmpty_1add_False()
{
Queue<object> queue = new Queue<object>();
queue.Push("string");
Assert.AreEqual(false, queue.IsEmpty());
}
示例11: Visit
/// <summary>
/// Converts rawPages to HTML documents.
/// </summary>
/// <param name="page">The page being converted.</param>
public void Visit(Page page)
{
if (page == null)
{
throw new ArgumentNullException("page");
}
if (page.RawPage == null)
{
return;
}
var doc = new HtmlDocument();
doc.LoadHtml(page.RawPage.TextData);
var comparedNode = doc.DocumentNode;
if (referenceNode == null)
{
var rdoc = new HtmlDocument();
rdoc.LoadHtml(page.RawPage.TextData);
referenceNode = rdoc.DocumentNode;
}
else
{
var refQueue = new Queue<HtmlNode[]>();
refQueue.Enqueue(new[] { referenceNode });
var comQueue = new Queue<HtmlNode[]>();
comQueue.Enqueue(new[] { comparedNode });
while (refQueue.Count > 0)
{
var refNodes = refQueue.Dequeue();
var comNodes = new Queue<HtmlNode>(comQueue.IsEmpty() ? new HtmlNode[0] : comQueue.Dequeue());
foreach (var refNode in refNodes)
{
var comNode = comNodes.DequeueWhile(n => !NodeEqualtyCompaper.Equals(n, refNode));
if (comNode != null)
{
refQueue.Enqueue(refNode.ChildNodes.ToArray());
comQueue.Enqueue(comNode.ChildNodes.ToArray());
}
else
{
refNode.Remove();
}
}
}
}
}
示例12: IsEmpty_True_Test
public void IsEmpty_True_Test()
{
var queue = new Queue<int>();
Assert.IsTrue(queue.IsEmpty());
}