本文整理汇总了C#中LinkedList.RemoveLast方法的典型用法代码示例。如果您正苦于以下问题:C# LinkedList.RemoveLast方法的具体用法?C# LinkedList.RemoveLast怎么用?C# LinkedList.RemoveLast使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类LinkedList
的用法示例。
在下文中一共展示了LinkedList.RemoveLast方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AbsoluteNormalizePath
public static String AbsoluteNormalizePath(String Path, String CurrentWorkingPath = "")
{
var Components = new LinkedList<String>();
// Normalize slashes.
Path = Path.Replace('\\', '/');
// Relative Path
if (Path.StartsWith("/"))
{
Path = CurrentWorkingPath + "/" + Path;
}
// Normalize Components
foreach (var Component in Path.Split('/'))
{
switch (Component)
{
case "": case ".": break;
case "..": Components.RemoveLast(); break;
default: Components.AddLast(Component); break;
}
}
return String.Join("/", Components).TrimStart('/');
}
示例2: MapDestinationPropertyToSource
public bool MapDestinationPropertyToSource(IProfileConfiguration options, TypeDetails sourceType, Type destType, Type destMemberType, string nameToSearch, LinkedList<IMemberGetter> resolvers, IMemberConfiguration parent )
{
string[] matches = DestinationMemberNamingConvention.SplittingExpression
.Matches(nameToSearch)
.Cast<Match>()
.Select(m => SourceMemberNamingConvention.ReplaceValue(m))
.ToArray();
MemberInfo matchingMemberInfo = null;
for (int i = 1; i <= matches.Length; i++)
{
NameSnippet snippet = CreateNameSnippet(matches, i);
matchingMemberInfo = parent.NameMapper.GetMatchingMemberInfo(sourceType, destType, destMemberType, snippet.First);
if (matchingMemberInfo != null)
{
resolvers.AddLast(matchingMemberInfo.ToMemberGetter());
var details = new TypeDetails(matchingMemberInfo.GetMemberType(), options);
var foundMatch = parent.MapDestinationPropertyToSource(options, details, destType, destMemberType, snippet.Second, resolvers);
if (!foundMatch)
resolvers.RemoveLast();
else
break;
}
}
return matchingMemberInfo != null;
}
示例3: Map
public static void Map(TodoistResources res)
{
var projects = res.Projects.OrderBy(p => p.ItemOrder);
var lastProject = projects.First();
int lastIndent = lastProject.Indent;
int lastOrder = lastProject.ItemOrder;
LinkedList<Project> projectParentage = new LinkedList<Project>();
foreach (var project in projects)
{
if (project.Indent > lastProject.Indent)
{
projectParentage.AddLast(lastProject);
}
else if (project.Indent < lastProject.Indent)
{
int indent = project.Indent;
while (++indent <= lastProject.Indent)
{
projectParentage.RemoveLast();
}
}
var parent = projectParentage.Last?.Value;
if (parent != null)
{
UpdateProjectHierarchy(parent, project);
}
UpdateProjectItemsHierarchy(project, res);
lastProject = project;
}
}
示例4: Main
static void Main()
{
var list = new LinkedList<int>();
list.AddLast(1);
Console.WriteLine(list);
list.AddLast(2);
Console.WriteLine(list);
list.AddLast(3);
Console.WriteLine(list);
list.AddFirst(-1);
Console.WriteLine(list);
list.AddFirst(-2);
Console.WriteLine(list);
list.AddFirst(-3);
Console.WriteLine(list);
Console.WriteLine("Remove First: {0}", list.RemoveFirst().Value);
Console.WriteLine("Remove Last: {0}", list.RemoveLast().Value);
Console.WriteLine(list);
Console.WriteLine("Min: {0}; Max: {1}", list.Min(), list.Max());
Console.WriteLine("Contains 2: {0}", list.Contains(2));
Console.WriteLine("Count: {0}", list.Count);
}
示例5: readPassword
private static string readPassword()
{
var passwordList = new LinkedList<char>();
bool reading_pwd = true;
while (reading_pwd)
{
ConsoleKeyInfo info = Console.ReadKey(true);
switch (info.Key)
{
case ConsoleKey.Enter:
reading_pwd = false;
break;
case ConsoleKey.Delete:
case ConsoleKey.Backspace:
if (false == passwordList.IsNullOrEmpty())
{
Console.Write("\b \b");
passwordList.RemoveLast();
}
break;
default:
passwordList.AddLast(info.KeyChar);
Console.Write('*');
break;
}
}
return String.Join("", passwordList);
}
示例6: SashaAndKate
static void SashaAndKate()
{
var input = Console.ReadLine().Split().ToArray();
string n = input[0];
int k = int.Parse(input[1]);
var p = new LinkedList<char>(n);
var current = p.First;
while (0 < k && current != p.Last)
{
var next = current.Next;
if (current.Value < next.Value)
{
//p.RemoveFirst();
p.Remove(current);
k--;
//current = p.First;
current = next.Previous ?? p.First;
}
else
{
current = next;
}
}
while (0 < k--)
p.RemoveLast();
foreach (char node in p)
Console.Write(node);
}
示例7: FieldPhraseList
/// <summary>
/// a constructor.
/// </summary>
/// <param name="fieldTermStack">FieldTermStack object</param>
/// <param name="fieldQuery">FieldQuery object</param>
public FieldPhraseList(FieldTermStack fieldTermStack, FieldQuery fieldQuery)
{
String field = fieldTermStack.GetFieldName();
LinkedList<TermInfo> phraseCandidate = new LinkedList<TermInfo>();
QueryPhraseMap currMap = null;
QueryPhraseMap nextMap = null;
while (!fieldTermStack.IsEmpty())
{
phraseCandidate.Clear();
TermInfo ti = fieldTermStack.Pop();
currMap = fieldQuery.GetFieldTermMap(field, ti.GetText());
// if not found, discard top TermInfo from stack, then try next element
if (currMap == null) continue;
// if found, search the longest phrase
phraseCandidate.AddLast(ti);
while (true)
{
ti = fieldTermStack.Pop();
nextMap = null;
if (ti != null)
nextMap = currMap.GetTermMap(ti.GetText());
if (ti == null || nextMap == null)
{
if (ti != null)
fieldTermStack.Push(ti);
if (currMap.IsValidTermOrPhrase(new List<TermInfo>(phraseCandidate)))
{
AddIfNoOverlap(new WeightedPhraseInfo(phraseCandidate, currMap.GetBoost(), currMap.GetTermOrPhraseNumber()));
}
else
{
while (phraseCandidate.Count > 1)
{
TermInfo last = phraseCandidate.Last.Value;
phraseCandidate.RemoveLast();
fieldTermStack.Push(last);
currMap = fieldQuery.SearchPhrase(field, new List<TermInfo>(phraseCandidate));
if (currMap != null)
{
AddIfNoOverlap(new WeightedPhraseInfo(phraseCandidate, currMap.GetBoost(), currMap.GetTermOrPhraseNumber()));
break;
}
}
}
break;
}
else
{
phraseCandidate.AddLast(ti);
currMap = nextMap;
}
}
}
}
示例8: Solve
// Looks like I ended up with the typical sliding-window deque solution. Here's an example for k = 3:
// 1 3 2 8 4 7 2, initialize left looking dominators like {3, 2}. These dominate everything to their
// left until a bigger dominator. Leftmost dominator goes to max value for subarray.
// [1 3 2] 8 4 7 2, {3, 2}
// 1 [3 2 8] 4 7 2, {8}, lost 1 but it wasn't a dominator, gained 8 and it dominates everything, kills 3 and 2.
// 1 3 [2 8 4] 7 2, {8, 4}, lost 3 but wasn't a dominator, gained 4 which dominates til 8.
// 1 3 2 [8 4 7] 2, {8, 7}, lost 2 but wasn't a dominator, gained 7 which kills 4 and domaintes til 8.
// 1 3 2 8 [4 7 2], {7, 2}, lost 8 so pop it off, gained 2 which dominates til 7.
// I say dominate because if you're an element and there's an element in your sliding window to your right
// that's greater than you (dominating you), you're never going to be the max for any of your remaining subarrays.
// That dominating element to your right will always be there until you're kicked out of the window.
// When a big number slides in it can dominate all of the dominators and be the only one left; the existing
// dominators would be to its left so they'd never be able to be the max for any remaining subarrays.
// We have to keep track of the dominators to the right of other, larger dominators because those other dominators
// are going to slide out before the ones to their right, and we need to know where to pick up from. It should be
// clear the dominators are always sorted, descending, from left to right. Dominators could be thought of recursively
// as greatest element in subarray, followed by greatest element in subarray to that element's right, etc. O(n)
// because we add or remove an array element from the dominators at most one time.
public static int[] Solve(int[] array, int k)
{
if (k == array.Length) return new[] { array.Max() };
if (k == 1) return array;
// Initializing the dominators for the first subarray. Gotta have the rightmost, then the next to the left that's
// larger than (or equal to) it, and so on. Equal to because we need the next one after an equal one is popped off.
var leftLookingDominators = new LinkedList<int>();
leftLookingDominators.AddFirst(array[k - 1]);
for (int i = k - 2; i >= 0; --i)
{
if (array[i] >= leftLookingDominators.Last.Value)
{
leftLookingDominators.AddLast(array[i]);
}
}
// Each iteration we're looking at the next subarray, slid over from the previous. We lose an element during the
// slide which might've been the leftmost dominator (the leftmost dominator is the only one that can be lost). We
// gain an element which might start dominating everything, or just some dominators til hitting some dominator to its
// left that's greater than it, or just itself. Don't have to worry about dominators ever becoming empty, because
// base case handled above. Even for k = 2, if there's only 1 dominator going in to the next iteration, it must be
// the rightmost element of the previous subarray, so it's not going to get popped off the end until the next next iteration.
int subarrayCount = array.Length - k + 1;
int[] subarrayMaximums = new int[subarrayCount];
subarrayMaximums[0] = leftLookingDominators.Last.Value;
for (int i = 1, j = k; i < subarrayCount; ++i, ++j)
{
int lostLeftValue = array[i - 1];
int gainedRightValue = array[j];
if (lostLeftValue == leftLookingDominators.Last.Value)
{
leftLookingDominators.RemoveLast();
}
if (gainedRightValue > leftLookingDominators.Last.Value)
{
leftLookingDominators.Clear();
leftLookingDominators.AddFirst(gainedRightValue);
}
else
{
while (gainedRightValue > leftLookingDominators.First.Value)
{
leftLookingDominators.RemoveFirst();
}
leftLookingDominators.AddFirst(gainedRightValue);
}
subarrayMaximums[i] = leftLookingDominators.Last.Value;
}
return subarrayMaximums;
}
示例9: TestRemoveLastMethod
public void TestRemoveLastMethod()
{
LinkedList<string> list = new LinkedList<string>();
var item1 = list.AddLast("John");
var item2 = list.AddLast("Joe");
var item3 = list.AddLast("Jo");
var item4 = list.AddLast("Bradly");
var item5 = list.AddLast("Charley");
list.RemoveLast();
list.RemoveLast();
Assert.AreEqual(3, list.Count);
Assert.AreSame(item1, list.First);
Assert.AreSame(item2, list.First.Next);
Assert.AreSame(item3, list.First.Next.Next);
}
示例10: Main
public static void Main()
{
LinkedList<int> list = new LinkedList<int>();
list.AddAtTheEnd(5);
list.AddAtTheEnd(10);
list.AddAtTheEnd(20);
list.AddAtTheEnd(30);
list.AddAtBeggining(1000);
list.RemoveFirst();
list.RemoveLast();
}
示例11: addGuardedPoint
private void addGuardedPoint(DateTime time, int bytes, LinkedList<KeyValuePair<DateTime, int>> rate)
{
lock (rate)
{
rate.AddFirst(new KeyValuePair<DateTime, int>(time, bytes));
if (rate.Count >= averageSize)
{
rate.RemoveLast();
}
}
}
示例12: Main
static void Main()
{
LinkedList<int> ints = new LinkedList<int>(4);
ints.AddFirst(3);
ints.AddLast(5);
ints.AddBefore(1, 1);
ints.AddAfter(2, 0);
ints.RemoveFirst();
ints.RemoveLast();
Console.WriteLine(ints.GetItemAt(0).Value);
}
示例13: IsStabilized
static Func<Point, bool> IsStabilized()
{
const int maxVariance = 50;
var last10 = new LinkedList<Point>(new Point(0, 0).Repeat(50));
return currentPosition =>
{
last10.RemoveLast();
last10.AddFirst(currentPosition);
var xVariance = last10.Max(p => p.X) - last10.Min(p => p.X);
var yVariance = last10.Max(p => p.Y) - last10.Min(p => p.Y);
return xVariance < maxVariance && yVariance < maxVariance;
};
}
示例14: CreateRequest
public static IRequest CreateRequest(ISocket socket, LinkedList<ArraySegment<byte>> headerBuffers)
{
var bodyDataReadWithHeaders = headerBuffers.Last.Value;
headerBuffers.RemoveLast();
var headersString = headerBuffers.GetString();
var reader = new StringReader(headersString);
var requestLine = reader.ReadRequestLine();
var headers = reader.ReadHeaders();
var context = new Dictionary<string, object>();
return new KayakRequest(socket, requestLine, headers, context, bodyDataReadWithHeaders);
}
示例15: IsStabilized
static Func<Zipping.Pair<int, int>, bool> IsStabilized()
{
const int maxVariance = 50;
var last10 = new LinkedList<Zipping.Pair<int, int>>(new Zipping.Pair<int, int>(0, 0).Repeat(10));
return currentPosition =>
{
last10.RemoveLast();
last10.AddFirst(currentPosition);
var xVariance = last10.Max(p => p.First) - last10.Min(p => p.First);
var yVariance = last10.Max(p => p.Second) - last10.Min(p => p.Second);
return xVariance < maxVariance && yVariance < maxVariance;
};
}