本文整理汇总了C#中Queue.Dequeue方法的典型用法代码示例。如果您正苦于以下问题:C# Queue.Dequeue方法的具体用法?C# Queue.Dequeue怎么用?C# Queue.Dequeue使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Queue
的用法示例。
在下文中一共展示了Queue.Dequeue方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Trim
internal static void Trim(bool stripEdids, bool stripRefs, string In, string Out, ReportProgressDelegate del)
{
Plugin p=new Plugin(In, false);
del("Editing plugin");
Queue<Rec> queue=new Queue<Rec>(p.Records);
while(queue.Count>0) {
if(queue.Peek() is Record) {
Record r=(Record)queue.Dequeue();
if(stripEdids) {
//if(r.SubRecords.Count>0&&r.SubRecords[0].Name=="EDID") r.SubRecords.RemoveAt(0);
for(int i=0;i<r.SubRecords.Count;i++) {
//if(r.SubRecords[i].Name=="SCTX") r.SubRecords.RemoveAt(i--);
}
}
} else {
GroupRecord gr=(GroupRecord)queue.Dequeue();
if(gr.ContentsType!="GMST") {
foreach(Rec r in gr.Records) queue.Enqueue(r);
}
}
}
del("Generating new esm");
//deflater=new ICSharpCode.SharpZipLib.Zip.Compression.Deflater(9);
BinaryWriter bw=new BinaryWriter(File.Create(Out));
p.SaveData(bw);
/*foreach(Rec r in p.Records) {
if(r is GroupRecord) WriteGroup(bw, (GroupRecord)r);
else WriteRecord(bw, (Record)r);
}*/
bw.Close();
}
示例2: Main
static void Main()
{
string input = Console.ReadLine();
string[] elements = input.Split(' ');
Queue<string> q = new Queue<string>();
for (int i = 0; i < elements.Length; i++)
{
q.Enqueue(elements[i]);
}
string a = q.Peek();
Console.Write(q.Dequeue());
while (q.Count > 0)
{
if (q.Peek() == a)
{
Console.Write(" " + q.Dequeue());
}
else
{
Console.WriteLine();
a = q.Peek();
Console.Write(q.Dequeue());
}
}
}
示例3: ChunkRangesBySize
public static IEnumerable<IndexRange> ChunkRangesBySize(IEnumerable<IndexRange> extents, int pageSizeInBytes)
{
var extentRanges = extents.SelectMany(e => e.PartitionBy(pageSizeInBytes));
var extentQueue = new Queue<IndexRange>(extentRanges);
if (extentQueue.Count == 0)
{
yield break;
}
// move to next start position
do
{
var result = extentQueue.Dequeue();
while (result.Length < pageSizeInBytes && extentQueue.Count > 0)
{
var nextRange = extentQueue.Peek();
if (!nextRange.Abuts(result))
{
break;
}
var mergedRange = nextRange.Merge(result);
if (mergedRange.Length <= pageSizeInBytes)
{
result = mergedRange;
extentQueue.Dequeue();
}
else
{
break;
}
}
yield return result;
} while (extentQueue.Count > 0);
}
示例4: ShortestDistance
Int32 ShortestDistance(Char[,] map)
{
Int32 i, j, sh, shi, shj, n = map.GetLength(0), m = map.GetLength(1);
Int32[,] dist = new Int32[n, m];
for (i = 0; i < n; ++i) {
for (j = 0; j < m; ++j) {
dist[i, j] = -1;
}
}
dist[0, 0] = 0;
Queue<Int32> qu = new Queue<Int32>();
qu.Enqueue(0);
qu.Enqueue(0);
while (qu.Count != 0) {
i = qu.Dequeue();
j = qu.Dequeue();
if (map[i, j] == 'x') {
return dist[i, j];
}
for (sh = 0; sh < 4; ++sh) {
shi = i + shift[sh, 0];
shj = j + shift[sh, 1];
if (shi >= 0 && shj >= 0 && shi < n && shj < m && map[shi, shj] != '#' && dist[shi, shj] < 0) {
dist[shi, shj] = dist[i, j] + 1;
qu.Enqueue(shi);
qu.Enqueue(shj);
}
}
}
return -1;
}
示例5: GetSequence
private static List<int> GetSequence(int n, int maxCount)
{
var queue = new Queue<int>();
var sequence = new List<int>();
queue.Enqueue(n);
int count = 1;
while (count <= maxCount)
{
int current = queue.Dequeue();
sequence.Add(current);
queue.Enqueue(current + 1);
queue.Enqueue((2 * current) + 1);
queue.Enqueue(current + 2);
count += 3;
}
while (count > maxCount)
{
queue.Dequeue();
count--;
}
sequence.AddRange(queue);
return sequence;
}
示例6: PolishNotation
// Polish Notation algorithm - calculating expression in the output queue
static Stack<double> PolishNotation(Queue<char> output)
{
Stack<double> exp = new Stack<double>();
while (output.Count > 0)
{
char symbol = output.Dequeue();
if (Char.IsDigit(symbol))
{
string num = "";
while (Char.IsDigit(symbol) || symbol == '.')
{
num += symbol;
symbol = output.Dequeue();
}
double number = double.Parse(num);
exp.Push(number);
}
if (symbol != ' ' && symbol != ',')
{
exp.Push(CalculateExpression(symbol, exp));
}
}
return exp;
}
示例7: Max_of_one_with_call_count_3_allows_only_one_call_at_a_time_for_3_iterations
public void Max_of_one_with_call_count_3_allows_only_one_call_at_a_time_for_3_iterations()
{
Queue<TaskCompletionSource<bool>> pending = new Queue<TaskCompletionSource<bool>>();
Func<Task> doAsync = delegate
{
TaskCompletionSource<bool> tcs = new TaskCompletionSource<bool>();
pending.Enqueue(tcs);
Assert.Equal(1, pending.Count);
return tcs.Task;
};
ParallelOperationManager manager = new ParallelOperationManager(1, doAsync);
Task task = manager.RunAsync(3);
Assert.False(task.IsCompleted);
Assert.Equal(1, pending.Count);
TaskCompletionSource<bool> current = pending.Dequeue();
current.SetResult(false);
Assert.False(task.IsCompleted);
Assert.Equal(1, pending.Count);
current = pending.Dequeue();
current.SetResult(false);
Assert.False(task.IsCompleted);
Assert.Equal(1, pending.Count);
current = pending.Dequeue();
current.SetResult(false);
Assert.Equal(TaskStatus.RanToCompletion, task.Status);
Assert.Equal(0, pending.Count);
}
示例8: PlayNextItem
public void PlayNextItem(Queue<FileNode> queue, VideoPlayerController controller, IPlayStrategy strategy, IPlayable previous)
{
if (!controller.Queue.IsEmpty())
{
var file = queue.Dequeue();
controller.Play(file);
if (file.Type == FileType.Audio && queue.Peek().Type != FileType.Audio)
{
controller.Play(queue.Dequeue());
}
}
else if (strategy.Repeat)
{
previous.Play(strategy, controller);
}
else if (previous is Player)
{
var playlist = _processor.Process(new GetGoalPlayListQuery());
if (playlist == null) return;
controller.Play(playlist, new PlayListPlayStrategy());
}
else if (controller.AutoPlayList)
{
var playlist = _processor.Process(new GetAutoPlayListQuery());
if (playlist == null) return;
playlist.Play(null, controller);
}
}
示例9: TriangleEntity
public TriangleEntity(Guid id,CustomType.Polygon polygon)
: base(id)
{
_Polygon = polygon;
var points = new Queue<CustomType.Vector2>(_Polygon.Points);
var firstPoint = points.Dequeue();
float top = firstPoint.Y;
float down = firstPoint.Y ;
float left = firstPoint.X;
float right = firstPoint.X;
while (points.Count > 0)
{
var point = points.Dequeue();
if (point.X > right)
{
right = point.X;
}
if (point.X < left)
{
left = point.X;
}
if (point.Y < top)
{
top = point.Y;
}
if (point.Y > down)
{
down = point.Y;
}
}
_QuadTreeObjectAbility = new PhysicalAbility(new Regulus.CustomType.Rect(left , top , right - left , down - top ) , this);
_Polygon.BuildEdges();
}
示例10: PosTest1
public bool PosTest1()
{
bool retVal = true;
TestLibrary.TestFramework.BeginScenario("PosTest1: Test whether ctor(IEnumerable<T>) is successful when passing string array.");
try
{
string[] TestArray = { "first", "second" };
Queue<string> TestQueue = new Queue<string>(TestArray);
if (TestQueue == null || TestQueue.Count != 2)
{
TestLibrary.TestFramework.LogError("P01.1", "ctor(IEnumerable<T>) failed when passing string array!");
retVal = false;
}
string element1 = TestQueue.Dequeue();
string element2 = TestQueue.Dequeue();
if (element1 != "first" || element2 != "second")
{
TestLibrary.TestFramework.LogError("P01.2", "ctor(IEnumerable<T>) failed when passing string array!");
retVal = false;
}
}
catch (Exception e)
{
TestLibrary.TestFramework.LogError("P01.3", "Unexpected exception: " + e);
TestLibrary.TestFramework.LogVerbose(e.StackTrace);
retVal = false;
}
return retVal;
}
示例11: Start
/*Mobile doesnt seem to allow for an Instatiation of a not saved object. So I copied a generated skyline with now fixed height and render that one differently each time
*/
#if UNITY_STANDALONE || UNITY_WEBPLAYER
void Start()
{
//Generation:
if (allColours.Length >= 2)
{
shuffledColors = new Queue<Color>(Utility.ShuffleArray(allColours, prgn.Next()));
foregroundColour = shuffledColors.Dequeue();
backgroundColour = shuffledColors.Dequeue();
}
else
{
foregroundColour = backgroundColour = allColours[0];
}
GenerateSkyline();
//Recycling-Start:
skyLineBlock1 = GameObject.Find("Generated Skyline");
if (skyLineBlock1 != null)
{
skyLineBlock2 = Instantiate(skyLineBlock1, skyLineBlock1.transform.position + Vector3.right* skyLineSize.x, Quaternion.identity) as GameObject;
skyLineBlock2.transform.parent = transform;
skyLineBlock2.transform.tag = "Skyline";
}
skylineBlockQueue = new Queue<GameObject>();
skylineBlockQueue.Enqueue(skyLineBlock1);
skylineBlockQueue.Enqueue(skyLineBlock2);
}
示例12: UseGenericQueue
static void UseGenericQueue()
{
// Make a Q with three people
Queue<Person> peopleQ = new Queue<Person>();
peopleQ.Enqueue(new Person { FirstName = "Homer", LastName = "Simpson", Age = 47 });
peopleQ.Enqueue(new Person { FirstName = "Marge", LastName = "Simpson", Age = 45 });
peopleQ.Enqueue(new Person { FirstName = "Lisa", LastName = "Simpson", Age = 9 });
// Peek at first person in Q.
Console.WriteLine("{0} is first in line !", peopleQ.Peek().FirstName);
// Remove each person from Q.
GetCoffee(peopleQ.Dequeue());
GetCoffee(peopleQ.Dequeue());
GetCoffee(peopleQ.Dequeue());
// Try to de-Q again?
try
{
GetCoffee(peopleQ.Dequeue());
}
catch (InvalidOperationException ex)
{
Console.WriteLine("Error! {0}", ex.Message);
}
}
示例13: Main
static void Main(string[] args)
{
long n = long.Parse(Console.ReadLine());
long s = n;
Queue<long> queue = new Queue<long>();
queue.Enqueue(s);
Console.Write(s+" ");
for (int i = 0; i < 16; i++)
{
s = queue.Dequeue();
queue.Enqueue(s+1);
Console.Write("{0} ",s+1);
queue.Enqueue((2*s)+1);
Console.Write("{0} ", (2 * s) + 1);
queue.Enqueue(s+2);
Console.Write("{0} ", s + 2);
}
s = queue.Dequeue();
while (queue.Count > 1)
{
queue.Dequeue();
}
Console.WriteLine("{0} ", s +1);
}
示例14: MirrorTree
private void MirrorTree(Node root){
var f = new Queue<Node>();
var s = new Queue<Node>();
if(root!= null) f.Enqueue(root);
if(root.Right != null) s.Enqueue(root.Right);
if(root.Left != null) s.Enqueue(root.Left);
while(s.Count != 0){
var r = f.Dequeue();
Console.WriteLine("Dealing with "+r.Data);
bool right = r.Right != null;
bool left = r.Left != null;
if(right){
var c = s.Dequeue();
QueueChildren(s, c, forward: false);
f.Enqueue(c);
Console.WriteLine("Assigning "+c.Data+" to left of "+r.Data);
r.Left = c;
}
if(left){
var c = s.Dequeue();
QueueChildren(s, c, forward: false);
f.Enqueue(c);
Console.WriteLine("Assigning "+c.Data+" to right of "+r.Data);
r.Right = c;
}
}
}
示例15: DeserializeFromText
public static MarkovChain DeserializeFromText(string text, Random r)
{
var chain = new MarkovChain(r);
var textQueue = new Queue<string>(text.Split(new []{Constants.MainSeparator}, StringSplitOptions.RemoveEmptyEntries));
// Get the name type
chain.ChainName = textQueue.Dequeue();
// Get the terminator and LettersToKeep
chain.TerminatorCharacter = textQueue.Dequeue()[0];
chain.LettersToKeep = int.Parse(textQueue.Dequeue());
// Get all the links
do
{
var prefixString = textQueue.Dequeue();
var suffixString = textQueue.Dequeue();
var link = MarkovLink<char>.DeserializeFromText(prefixString,
suffixString,
Constants.SecondarySeparator,
r);
chain._links.Add(link.GetHashCode(), link);
} while (textQueue.Count > 0);
return chain;
}