本文整理汇总了C#中System.Collections.Stack.Push方法的典型用法代码示例。如果您正苦于以下问题:C# Stack.Push方法的具体用法?C# Stack.Push怎么用?C# Stack.Push使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Collections.Stack
的用法示例。
在下文中一共展示了Stack.Push方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: InvokeViewShared
private ViewResult InvokeViewShared(string viewType, object model = null, string viewName = null)
{
Stack parameters = new Stack();
if (model == null)
{
if (viewName == null)
{
}
else
{
parameters.Push(viewName);
}
}
else
{
if (viewName == null)
{
parameters.Push(model);
}
else
{
parameters.Push(viewName);
parameters.Push(model);
}
}
return (ViewResult)_controller.GetType().GetMethod(viewType, System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic, null, parameters.Cast<Object>().Select(p => p.GetType()).ToArray(), null).Invoke(_controller, parameters.ToArray());
}
示例2: LongestValidParentheses
public int LongestValidParentheses(string s)
{
Stack<int> stack = new Stack<int>();
char[] arr = s.ToCharArray();
int result = 0;
for (int i = 0; i < arr.Length; i++)
{
if (arr[i] == '(')
{
stack.Push(i);
}
else
{
if (stack.Count != 0 && arr[stack.Peek()] == '(')
{
stack.Pop();
result = Math.Max((stack.Count == 0 ? i + 1 : i - stack.Peek()), result);
}
else
{
stack.Push(i);
}
}
}
return result;
}
示例3: PerformAnalysis
public void PerformAnalysis(BasicBlocks basicBlocks)
{
// Create dictionary of referenced blocks
Dictionary<BasicBlock, int> referenced = new Dictionary<BasicBlock, int>(basicBlocks.Count);
// Allocate list of ordered Blocks
blockOrder = new BasicBlock[basicBlocks.Count];
int orderBlockCnt = 0;
// Create sorted worklist
var workList = new Stack<BasicBlock>();
foreach (var head in basicBlocks.HeadBlocks)
{
workList.Push(head);
while (workList.Count != 0)
{
var block = workList.Pop();
if (!referenced.ContainsKey(block))
{
referenced.Add(block, 0);
blockOrder[orderBlockCnt++] = block;
foreach (var successor in block.NextBlocks)
if (!referenced.ContainsKey(successor))
workList.Push(successor);
}
}
}
}
示例4: Main_7_9_6
//Main_7_9_6
public static void Main_7_9_6()
{
Queue myQueue = new Queue();
//��Queueβ�����Ԫ��
myQueue.Enqueue("��");
myQueue.Enqueue("��");
myQueue.Enqueue("˭");
//����Queueu��ʼ��Ԫ��
Console.WriteLine(myQueue.Peek());
//���ز��Ƴ�Queue��ʼ��Ԫ��
myQueue.Dequeue();
//����Queue
foreach (object o in myQueue)
Console.WriteLine(o.ToString());
Stack myStack = new Stack();
//��Stack��������Ԫ��
myStack.Push("��");
myStack.Push("��");
myStack.Push("˭");
//����Stack������Ԫ��
Console.WriteLine(myStack.Peek());
//���ز��Ƴ�Stack������Ԫ��
myStack.Pop();
//����Stack
foreach (object o in myStack)
Console.WriteLine(o.ToString());
}
示例5: Calculate
public int Calculate(string rpn)
{
string[] parts = rpn.Split(' ');
var stack = new Stack<int>();
foreach (string part in parts)
{
int digit;
bool isDigit = int.TryParse(part, out digit);
if (isDigit)
{
stack.Push(digit);
continue;
}
bool isOperator = Array.IndexOf(operators, part) >= 0;
if (isOperator)
{
int digit2 = stack.Pop();
int digit1 = stack.Pop();
int value = InternalCalcul(digit1, digit2, part);
stack.Push(value);
}
}
return stack.Pop();
}
示例6: Draw
protected override void Draw(GameTime gameTime)
{
if (G.currentGame.Count == 0)
return;
Stack<GameType> buffer = new Stack<GameType>();
GraphicsDevice.Clear(Color.Black);
while (G.currentGame.Count != 1 && !G.currentGame.Peek().IsFullScreen)
buffer.Push(G.currentGame.Pop());
buffer.Push(G.currentGame.Pop());
G.spriteBatch.Begin();
while (buffer.Count != 0)
{
buffer.Peek().Draw();
G.currentGame.Push(buffer.Pop());
}
Cursor.Draw();
black.Draw();
white.Draw();
G.spriteBatch.End();
base.Draw(gameTime);
}
示例7: F1
private static void F1(string path)
{
Stack<string> dir = new Stack<string>(); /// Создаю стэк из строк, при этом не указывая размер
Console.WriteLine(path + ":" + Directory.GetFiles(path).Length);
/// Выводим количество файлов
/// в главной папке
if (Directory.Exists(path))
{
dir.Push(path); /// Если папка с таким названием есть на компьютере, то добавляем ее в стэк
}
else
{
Console.WriteLine("Error!No such directory in a computer!!!"); /// Если нет, выводим сообщение об ошибке
}
/// Условие, что пока в стэке есть элементы, продолжать действия
while (dir.Count > 0)
{
string[] subDirs = Directory.GetDirectories(dir.Pop()); /// Массив из строк (подпапки)
foreach (string s in subDirs) /// Находим количество файлов в папках через foreach
{
Console.WriteLine(s + ": " + Directory.GetFiles(s).Length);
dir.Push(s);
/// Закидываем папку в стэк и продолжаем действовать, до тех пор пока
/// while не пробежит все подпапки нашего заданного пути
}
}
}
示例8: Main
static void Main(string[] args)
{
int edad = 66;
Persona objetoPersona = new Persona("Persona", edad);
int legajo = 333;
//Alumno objetoAlumo = new Alumno(objetoPersona, legajo);
Alumno objetoAlumo = new Alumno(new Persona("alumno",77), legajo);
DateTime fechaEgreso = DateTime.Now;
//AlumnoEgresado objetoAlumnoEgresado = new AlumnoEgresado(objetoAlumo, fechaEgreso);
AlumnoEgresado objetoAlumnoEgresado = new AlumnoEgresado(new Alumno(22,8888," alumnoEgresado"),DateTime.Now);
Profesor objetoProfesor = new Profesor(new Persona("profesor",55), 999);
Persona[] conjuntoDePersonas= new Persona[4];
conjuntoDePersonas[0] = objetoPersona;
conjuntoDePersonas[1] = objetoAlumo;
conjuntoDePersonas[2] = objetoAlumnoEgresado;
conjuntoDePersonas[3] = objetoProfesor;
foreach (Persona item in conjuntoDePersonas)
{
Console.WriteLine(item.ToString());
}
//no genericas --- que no tienen genero , proceso inbox
ArrayList vector = new ArrayList();
vector.Add(3);
vector.Add(objetoAlumo);
vector.Add("alguna palabra");
int dato= vector.Capacity;
int dato2 = vector.Count;
Stack pilaDeDatos = new Stack();
pilaDeDatos.Push(1);
pilaDeDatos.Push(1);
}
示例9: button2_Click
private void button2_Click(object sender, EventArgs e)
{
//ʵ����
Stack myStack = new Stack();
//ʹ��Push������ջ
myStack.Push("A");
myStack.Push("B");
myStack.Push("C");
myStack.Push("C");
//����ջԪ��
Console.WriteLine("\nmyStack:");
foreach (string item in myStack)
{
Console.WriteLine("|_" + item);
}
//ʹ��Pop������ջ
Console.WriteLine("\nItem pulled from myStack: " + myStack.Pop().ToString());
Console.WriteLine("\nAfter myStack.Pop(),myStack:");
foreach (string item in myStack)
{
Console.WriteLine("|_" + item);
}
//Peek����ֻ����ջ��Ԫ�أ�����ջ��ɾ��
Console.WriteLine("\nmyStack.Peek() : " + myStack.Peek().ToString());
Console.WriteLine("\nAfter myStack.Peek(),myStack:");
foreach (string item in myStack)
{
Console.WriteLine("|_" + item);
}
}
示例10: CreateItemHierarchy
/// <summary>
/// Creates recursively the hierarchy for the given item.
/// Returns the complete hierarchy.
/// </summary>
/// <param name="itemHierarchy">The item hierarchy.</param>
/// <param name="item">The item.</param>
private static void CreateItemHierarchy(
Stack itemHierarchy,
object item)
{
ProjectItem projectItem = item as ProjectItem;
if (projectItem != null)
{
ProjectItem pi = projectItem;
itemHierarchy.Push(pi);
CreateItemHierarchy(itemHierarchy, pi.Collection.Parent);
}
else
{
Project project = item as Project;
if (project != null)
{
Project p = project;
itemHierarchy.Push(p);
if (p.ParentProjectItem != null)
{
//// top nodes dont have solution as parent, but is null
CreateItemHierarchy(itemHierarchy, p.ParentProjectItem);
}
}
}
}
示例11: RedBlackEnumerator
///<summary>
/// Determine order, walk the tree and push the nodes onto the stack
///</summary>
public RedBlackEnumerator(RedBlack redBlack, RedBlackNode tnode, bool keys, bool ascending)
{
this.stack = new Stack();
this.keys = keys;
this.ascending = ascending;
this.redBlack = redBlack;
// use depth-first traversal to push nodes into stack
// the lowest node will be at the top of the stack
if(ascending)
{ // find the lowest node
while (tnode != redBlack.sentinelNode)
{
stack.Push(tnode);
tnode = tnode.Left;
}
}
else
{
// the highest node will be at top of stack
while (tnode != redBlack.sentinelNode)
{
stack.Push(tnode);
tnode = tnode.Right;
}
}
}
示例12: ValidateDepth
private static void ValidateDepth(SelectExpandClause selectExpand, int maxDepth)
{
// do a DFS to see if there is any node that is too deep.
Stack<Tuple<int, SelectExpandClause>> nodesToVisit = new Stack<Tuple<int, SelectExpandClause>>();
nodesToVisit.Push(Tuple.Create(0, selectExpand));
while (nodesToVisit.Count > 0)
{
Tuple<int, SelectExpandClause> tuple = nodesToVisit.Pop();
int currentDepth = tuple.Item1;
SelectExpandClause currentNode = tuple.Item2;
if (currentNode.Expansion != null)
{
IEnumerable<ExpandItem> expandItems = currentNode.Expansion.ExpandItems;
if (expandItems.Any() && currentDepth == maxDepth)
{
throw new ODataException(
Error.Format(SRResources.MaxExpandDepthExceeded, maxDepth, "MaxExpansionDepth"));
}
IEnumerable<SelectExpandClause> children = expandItems.Select(i => i.SelectExpandOption);
foreach (SelectExpandClause child in children)
{
nodesToVisit.Push(Tuple.Create(currentDepth + 1, child));
}
}
}
}
示例13: Main
static void Main(string[] args)
{
// Declare stack collection
Stack myStack = new Stack();
// Push elements onto the stack
myStack.Push("item 1");
myStack.Push("item 2");
myStack.Push("item 3");
// Display number of items
Console.WriteLine("{0} Items on the stack", myStack.Count);
// Have a peek at the item on top
Console.WriteLine("{0}", myStack.Peek());
// Pop off an element
myStack.Pop(); // gets top value
// Have a peek at the item on top
Console.WriteLine("{0}", myStack.Peek());
// Clear stack
myStack.Clear();
// Display number of items
Console.WriteLine("{0} Items on the stack", myStack.Count);
Console.ReadLine();
}
示例14: Main
static void Main(string[] args)
{
// Stack - A LIFO collection
Stack<string> stack = new Stack<string>();
stack.Push("A"); // Push adds to the stack
stack.Push("B");
stack.Push("C");
stack.Push("D");
Console.WriteLine(stack.Peek()); // D - Peek returns the last added value without removing it
Console.WriteLine(stack.Pop()); // D - Pop returna the last added value and removes it
Console.WriteLine(stack.Peek()); // C
// Queue - A FIFO collection
Queue<string> queue = new Queue<string>();
queue.Enqueue("a"); // Enqueue adds to the queue
queue.Enqueue("b");
queue.Enqueue("c");
queue.Enqueue("d");
Console.WriteLine(queue.Peek()); // a - Peek returns the beginning value without removing it
Console.WriteLine(queue.Dequeue()); // a - Dequeue returns the beginning value and removes it
Console.WriteLine(queue.Peek()); // b
//--
Console.ReadKey();
}
示例15: Main
static void Main(string[] args)
{
Stack ast = new Stack();
ast.Push("Item 1");
ast.Push("Item 2");
ast.Push("Item 3");
ast.Push("Item 4");
Console.WriteLine("Count: {0}", ast.Count);
PrintValues(ast);
// Peek item but do not remove
object item = ast.Peek();
Console.WriteLine("Peek: {0}", item);
PrintValues(ast);
// Peek and cast but do not remove
string itemString = ast.Peek() as string; // fast cast
Console.WriteLine("Peek: {0}", item);
PrintValues(ast);
// Contains
Boolean contains = ast.Contains("Item 3");
Console.WriteLine("Contains: {0}", contains);
// Remove items
object item4 = ast.Pop();
object item3 = ast.Pop();
Console.WriteLine("Pop: {0} {1}", item4, item3);
PrintValues(ast);
Console.WriteLine("Count: {0}", ast.Count);
// no TrimToSize method
}