本文整理汇总了C#中Queue.ToList方法的典型用法代码示例。如果您正苦于以下问题:C# Queue.ToList方法的具体用法?C# Queue.ToList怎么用?C# Queue.ToList使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Queue
的用法示例。
在下文中一共展示了Queue.ToList方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CalculateAroon
//Aroon
public static void CalculateAroon(out string key, out string key2, StockPoints data, Dictionary<DateTime, Dictionary<string, double>> indicators, int period, out int offset)
{
key = string.Format("Aroon-UP({0})", period.ToString("00"));
key2 = string.Format("Aroon-Down({0})", period.ToString("00"));
offset = period - 1;
// Aroon-Up = ((period - Days Since period-day High)/period) x 100
double up;
// Aroon-Down = ((period - Days Since period-day Low)/period) x 100
double down;
// day since 25 day high
int high;
// day since 25 day low
int low;
Queue<double> highVals = new Queue<double>();
Queue<double> lowVals = new Queue<double>();
int i = 0;
foreach(StockPoint point in data)
{
highVals.Enqueue(point.High);
lowVals.Enqueue(point.Low);
if(highVals.Count > period)
{
highVals.Dequeue();
lowVals.Dequeue();
}
if (i < period - 1)
{
i++;
}
else
{
high = period - highVals.ToList().IndexOf(highVals.Max());
low = period - highVals.ToList().IndexOf(highVals.Min());
up = ((period - high) / (double)period) * 100;
down = ((period - low) / (double)period) * 100;
AddValue(point.PointDateTime, key, up, indicators);
AddValue(point.PointDateTime, key2, down, indicators);
}
}
}
示例2: Main
static void Main(string[] args)
{
if (args.Length < 3)
throw new ArgumentException("usage: ./bot nick server port [channel+]", "args");
var argQueue = new Queue<string>(args);
var nick = argQueue.Dequeue();
var server = argQueue.Dequeue();
var port = int.Parse(argQueue.Dequeue());
var chans = argQueue.ToList();
var client = new TcpClient(server, port);
var stream = client.GetStream();
var buffered = new BufferedStream(stream);
var input = new StreamReader(buffered, Encoding.UTF8);
var output = new StreamWriter(buffered, Encoding.UTF8);
var bot = new Bot
{
Nick = nick,
Server = server,
Input = input,
Output = output,
Channels = chans
};
bot.Run();
}
示例3: TimeZoneOffsetProvider
/// <summary>
/// Initializes a new instance of the <see cref="TimeZoneOffsetProvider"/> class
/// </summary>
/// <param name="timeZone">The time zone to provide offsets for</param>
/// <param name="utcStartTime">The start of the range of offsets</param>
/// <param name="utcEndTime">The en of the range of offsets</param>
public TimeZoneOffsetProvider(DateTimeZone timeZone, DateTime utcStartTime, DateTime utcEndTime)
{
_timeZone = timeZone;
// pad the end so we get the correct zone interval
utcEndTime += TimeSpan.FromDays(2*365);
var start = DateTimeZone.Utc.AtLeniently(LocalDateTime.FromDateTime(utcStartTime));
var end = DateTimeZone.Utc.AtLeniently(LocalDateTime.FromDateTime(utcEndTime));
var zoneIntervals = _timeZone.GetZoneIntervals(start.ToInstant(), end.ToInstant());
_discontinuities = new Queue<long>(zoneIntervals.Select(x => x.Start.ToDateTimeUtc().Ticks));
var disc = _discontinuities.ToList();
var t = new DateTime(disc[0]);
if (_discontinuities.Count == 0)
{
// end of discontinuities
_nextDiscontinuity = DateTime.MaxValue.Ticks;
_currentOffsetTicks = _timeZone.GetUtcOffset(Instant.FromDateTimeUtc(DateTime.UtcNow)).Ticks;
}
else
{
// get the offset just before the next discontinuity to initialize
_nextDiscontinuity = _discontinuities.Dequeue();
_currentOffsetTicks = _timeZone.GetUtcOffset(Instant.FromDateTimeUtc(new DateTime(_nextDiscontinuity - 1, DateTimeKind.Utc))).Ticks;
}
}
示例4: Stack
public static Queue<Sheet> Stack(string title, string url, Queue<Sheet> defaultStack, Queue<Sheet> currentStack)
{
Queue<Sheet> stack;
if (currentStack != null && currentStack.Count > 0) {
stack = new Queue<Sheet>(currentStack.ToList<Sheet>());
}
else {
if (defaultStack != null && defaultStack.Count > 0)
stack = new Queue<Sheet>(defaultStack.ToList<Sheet>());
else stack = new Queue<Sheet>();
}
List<Sheet> sheets = stack.ToList<Sheet>();
int index = sheets.FindIndex(delegate(Sheet sheet) {
return sheet.Url == url;
});
if (index > -1)
stack = new Queue<Sheet>(stack.Take<Sheet>(index));
stack.Enqueue(new Sheet() { Title = title, Url = url });
return stack;
}
示例5: Rifle
public Rifle(Sprite parent)
: base(parent, "rifle")
{
_magazine = new Queue<IBullet>();
_cache = new Queue<IBullet>();
Enumerable.Range(0, 20).ForEach(_ => _cache.Enqueue(new Bullet(this)));
SubSprites.AddRange(_cache.ToList());
}
示例6: RemoveFromQueue
public static Queue<UCWorm> RemoveFromQueue(UCWorm item, Queue<UCWorm> queue)
{
var list = queue.ToList();
list.Remove(item);
var finalQueue = new Queue<UCWorm>();
foreach (UCWorm i in list)
{
finalQueue.Enqueue(i);
}
return finalQueue;
}
示例7: StartDownload
private static void StartDownload()
{
string strConn = System.Configuration.ConfigurationManager.ConnectionStrings["DBModel.Properties.Settings.StockDataConnectionString"].ToString();
List<string> lstSymbol = new List<string>();
DateTime lastEndDate = Helper.GetEndDate(DateTime.Today);
using (StockDBDataContext dbContext = new StockDBDataContext(strConn))
{
lstSymbol = (from s in dbContext.StockSymbols
where ((s.EndDate < lastEndDate || s.EndDate==null) /*&& s.Symbol=="GLW"*/)
//and s.Symbol =="GLW"d
orderby s.Symbol
select s.Symbol).ToList();
}
var exceptions = new Queue<Exception>();
ParallelOptions pOptions = new ParallelOptions { MaxDegreeOfParallelism = 10 };
Parallel.ForEach(lstSymbol, pOptions, s =>
{
try
{
Console.WriteLine(string.Format("Processing {0}", s));
WorkflowInvoker.Invoke(
new PeakCalculater.QuoteDownload()
{
Symbol = s,
ConnString = strConn
}
);
}
catch (Exception e)
{
ApplicationException appExp = new ApplicationException(string.Format("Exception happend when processing {0}", s), e);
exceptions.Enqueue(appExp);
}
}
);
if (exceptions.Count > 0)
{
Helper.LogExceptions(exceptions.ToList());
Console.WriteLine("Check Exception");
Console.ReadLine();
}
else
Console.WriteLine("Completed");
}
示例8: CalculateExpressionInRPN
/// <summary>
/// Calculates an expression given in Reversed Polish Notation
/// </summary>
/// <param name="queue"></param>
/// <returns></returns>
public static double CalculateExpressionInRPN(Queue<object> queue)
{
try
{
List<object> list = new List<object>();
list = queue.ToList();
int index = 0;
while (list.Count > 1)
{
string type = list[index].GetType().ToString();
if (type == "System.String")
{
string item = list[index].ToString();
switch (item[0])
{
case '+': OperatorAdd(list, ref index); break;
case '-': OperatorSubtract(list, ref index); break;
case '*': OperatorMulty(list, ref index); break;
case '/': OperatorDivide(list, ref index); break;
case 'L':
case 'l': FunctionLn(list, ref index); break;
case 'S':
case 's': FunctionSqrt(list, ref index); break;
case 'P':
case 'p': FunctionPow(list, ref index); break;
default:
break;
}
}
index++;
}
return (double)list[0];
}
catch (InvalidCastException e)
{
throw new FormatException
("The input expression is not correct formated!", e);
}
catch (ArgumentOutOfRangeException e)
{
throw new FormatException
("The input expression is not correct formated!", e);
}
catch (IndexOutOfRangeException e)
{
throw new FormatException
("The input expression is not correct formated!", e);
}
}
示例9: MedianFilter
public static double MedianFilter(Queue<double> RSS)
{
List<double> RSSList = RSS.ToList();
RSSList.Sort();
//uneven
if (RSSList.Count % 2 != 0)
{
return RSSList[(RSSList.Count - 1)/2];
}
//even
else
{
return ((RSSList[(RSSList.Count/2) - 1] + RSSList[(RSSList.Count/2)])/2);
}
}
示例10: Should_call_source_and_seed_methods_asynchronously_but_in_the_proper_order
public void Should_call_source_and_seed_methods_asynchronously_but_in_the_proper_order()
{
var queue = new Queue<string>();
const int needListSize = 100;
var partialDataAccessSourceMock = new PartialDataAccessMock(RdcNeedType.Source.ToString(), queue);
var partialDataAccessSeedMock = new PartialDataAccessMock(RdcNeedType.Seed.ToString(), queue);
var needList = GenerateAlternatedNeeds(needListSize).ToList();
var result = NeedListParser.ParseAsync(partialDataAccessSourceMock, partialDataAccessSeedMock,
Stream.Null, needList, CancellationToken.None);
result.Wait();
var calls = queue.ToList();
for (var i = 0; i < needListSize; i++)
{
Assert.Equal(string.Format("{0}{1}", needList[i].BlockType, needList[i].BlockLength), calls[i]);
}
}
示例11: 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();
}
示例12: GetMaxActivitiesSelectorGreedyTail
public List<int> GetMaxActivitiesSelectorGreedyTail(int[] s, int[] f)
{
int n = s.Length;
_starts = new int[n + 2];
_finishes = new int[n + 2];
for (int i = 0; i < n; i++)
{
_starts[i + 1] = s[i];
_finishes[i + 1] = f[i];
}
_starts[n + 1] = int.MaxValue;
_counts = new int[n + 2, n + 2];
_splits = new int[n + 2, n + 2];
_pathGreedy = new Queue<int>();
CalculateMaxActivitiesSelectionGreedyTail(0, n + 1);
return _pathGreedy.ToList();
}
示例13: createContactLines
/// <summary>
/// Similar to createShadow() but in that it generates the
/// contacts lines used for colliding with shadows instead
/// of the graphical representation.
/// </summary>
/// <param name="type">Type of shadow</param>
/// <param name="side">Relative side</param>
/// <param name="rect">Rect casting the shadow</param>
/// <param name="source">Source of the light.</param>
/// <param name="windowSize">The minimum size of the space you want to cover (Typically the window size)</param>
/// <returns></returns>
public static List<Line> createContactLines(int type, int side, Rectangle rect, Vector2 source, Vector2 windowSize)
{
List<Line> contactLines = new List<Line>();
Queue<Vector2> cornerQueue = new Queue<Vector2>();
cornerQueue.Enqueue(new Vector2(rect.Right, rect.Top)); // 0
cornerQueue.Enqueue(new Vector2(rect.Right, rect.Bottom)); // 1
cornerQueue.Enqueue(new Vector2(rect.Left, rect.Bottom)); // 2
cornerQueue.Enqueue(new Vector2(rect.Left, rect.Top)); // 3
//dont need to rotate if its the first type of side.
if (side != 0)
{
//shift the corner 'side' times. (1-3)
for (int i = 0; i < side; i++)
{
Vector2 rotatedCorner = cornerQueue.Dequeue();
cornerQueue.Enqueue(rotatedCorner);
}
}
List<Vector2> cornerList = cornerQueue.ToList();
if (type == 2) //side or top
{
contactLines.Add(new Line(cornerList[0], projectPoint(source, cornerList[0], windowSize)));
contactLines.Add(new Line(cornerList[3], projectPoint(source, cornerList[3], windowSize)));
}
else if (type == 3) //diagonal corner
{
contactLines.Add(new Line(cornerList[0], projectPoint(source, cornerList[0], windowSize)));
contactLines.Add(new Line(cornerList[2], projectPoint(source, cornerList[2], windowSize)));
}
return contactLines;
}
示例14: NoFilter
/// <summary>
/// Fake RSS filter
/// Enables the use of the delegates even when no filter is used
/// </summary>
/// <param name="RSS"></param>
/// <returns></returns>
public static double NoFilter(Queue<double> RSS)
{
List<double> RSSList = RSS.ToList();
return RSSList[RSS.Count - 1];
}
示例15: SortQueueWithExpropriation
public static Queue<Process> SortQueueWithExpropriation(Queue<Process> queueProcess, int peekToGoTime)
{
queueProcess.Peek().CpuPhaseLength -= peekToGoTime;
var tempList = queueProcess.ToList();
var tempList2 = tempList.OrderBy(process => process.CpuPhaseLength);
var queueResult = new Queue<Process>();
foreach (var process in tempList2)
{
queueResult.Enqueue(process);
}
return queueResult;
}