本文整理汇总了C#中Stack.push方法的典型用法代码示例。如果您正苦于以下问题:C# Stack.push方法的具体用法?C# Stack.push怎么用?C# Stack.push使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Stack
的用法示例。
在下文中一共展示了Stack.push方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SortStack
public static void SortStack(Stack s)
{
Stack helper = new Stack();
helper.push(s.pop());
while (true)
{
if (helper.peek() < s.peek())
{
helper.push(s.pop());
}
if (s.getSize() == 0)
{
break;
}
double loop = s.pop();
while (loop < helper.peek())
{
s.push(helper.pop());
}
helper.push(loop);
}
while (helper.getSize() != 0)
{
s.push(helper.pop());
}
}
示例2: evaluatepostfixexp
public void evaluatepostfixexp(string s)
{
Stack stack=new Stack(s.Length);
char[] carr=s.ToCharArray();
foreach(char c in carr)
{
if(isDigit(c))
{
stack.push(c-'0');
Console.WriteLine(stack.peek());
}
else
{
int a =stack.pop();
int b=stack.pop();
switch(c)
{
case '+':stack.push(a+b);break;
case '-':stack.push(a-b);break;
case '*':stack.push(a*b);break;
case '/':stack.push(a/b);break;
}
}
}
Console.WriteLine(stack.peek());
}
示例3: Main
static void Main()
{
Stack s=new Stack();
s.push(1);
s.push(2);
s.push(3);
s.pop();
s.pop();
s.pop();
s.pop();
}
示例4: Main
public static void Main(string[] args)
{
int M = 5;
MinPQ<int> pq = new MinPQ<int>(M + 1);
//StreamReader fs = new StreamReader("tinyW.txt");
//StreamReader fs = new StreamReader("tinyT.txt");
//StreamReader fs = new StreamReader("largeW.txt");
StreamReader fs = new StreamReader("largeT.txt");
string line;
while (!fs.EndOfStream)
{
line = fs.ReadLine();
pq.insert(int.Parse(line));
// eliminam valoarea minima din coada cu prioritate daca sunt M+1 elemente in coada
if (pq.size() > M)
pq.delMin();
} // cele mai mari M elemente sunt in coada
// afisam elementele din coada cu prioritate in ordine inversa
Stack<int> stack = new Stack<int>();
foreach (var item in pq)
stack.push(item);
foreach (var item in stack)
{
Console.WriteLine(item);
}
}
示例5: Main
static void Main(string[] args)
{
// Print the top M lines in the input stream.
Console.Write("Write Lenth : ");
int M = int.Parse(Console.ReadLine());
Console.Write("Write Del max(True) or min(False) : ");
bool b = false;
bool.TryParse(Console.ReadLine(),out b);
PriorityQueue<int> pq = new PriorityQueue<int>(M,b);
Console.WriteLine("Insert Queue : ");
for(int i=0;i<M;i++)
pq.Insert(int.Parse(Console.ReadLine()));
Stack<int> stack = new Stack<int>();
while (!pq.isEmpty())
stack.push(pq.Del());
Console.WriteLine("\n\t OutPut Stack");
while(!stack.isEmpty())
Console.WriteLine(stack.pull());
Console.ReadKey();
}
示例6: Main
static void Main(string[] args)
{
Stack<int> stack = new Stack<int>();
stack.push(5);
stack.push(3);
stack.push(2);
stack.push(6);
stack.push(7);
stack = Sort(stack);
while (!stack.isEmpty()) {
Console.WriteLine(stack.pop());
}
}
示例7: Sort
//O(n^2) time, O(n) space
static Stack<int> Sort(Stack<int> stack)
{
Stack<int> stack2 = new Stack<int>();
while (!stack.isEmpty()) {
int temp = stack.pop();
while ((!stack2.isEmpty()) && (temp < stack2.peek()))
{
stack.push(stack2.pop());
}
stack2.push(temp);
}
while (!stack2.isEmpty())
stack.push(stack2.pop());
return stack;
}
示例8: move
public void move(int n, Stack destination, Stack loop, Stack original, bool first = true)
{
if (n==0)
{
return;
}
move(n - 1, loop, destination, original);
destination.push(original.pop());
move(n - 1, destination, original, loop);
}
示例9: Main
static void Main()
{
// Console.WriteLine("Enter string");
// string s=Console.ReadLine();
// Stack s1=new Stack(s.Length);
// s=s1.reverse(s);
// Console.WriteLine(s);
Stack s=new Stack(5);
s.push('a');
s.push('b');
s.push('c');
s.push('d');
s.push('e');
Console.WriteLine(s.peek());
s.stackReverse();
Console.WriteLine(s.pop());
Console.WriteLine(s.pop());
Console.WriteLine(s.pop());
Console.WriteLine(s.pop());
}
示例10: Main
public static void Main(string[] args)
{
Stack<int> st = new Stack<int>(3);
for (int i = 0; i < 10; i++)
st.push(i);
while (!st.isEmpty())
{
Console.WriteLine(st.pop());
}
}
示例11: Main
static void Main(string[] args)
{
string exp = "( 1 + ( ( 2 + 3 ) * ( 4 * 5 ) ) )";
string[] tokens = exp.Split(' ');
Stack<string> operatori = new Stack<string>();
Stack<double> operanzi = new Stack<double>();
foreach (var item in tokens)
{
if (item == "(")
;
else if (item == "+" || item == "-" || item == "*" || item == "/")
operatori.push(item);
else if (item == ")")
{
string op = operatori.pop();
double v = operanzi.pop();
switch (op)
{
case "+":
v = operanzi.pop() + v;
break;
case "-":
v = operanzi.pop() - v;
break;
case "/":
v = operanzi.pop() / v;
break;
case "*":
v = operanzi.pop() * v;
break;
}
operanzi.push(v);
}
else
operanzi.push(double.Parse(item));
}
Console.WriteLine("Valoarea expresiei este: {0}", operanzi.pop());
}
示例12: push
public void push(int value)
{
Stack<int> lastStack = getLastStack();
if (lastStack != null && !lastStack.isFull())
{
lastStack.push(value);
}
else {
Stack<int> stack = new Stack<int>(capacity);
stack.push(value);
stacks.Add(stack);
}
}
示例13: SortStackV5
public static Stack SortStackV5(Stack s)
{
Stack n = new Stack();
while (s.getSize() != 0)
{
double tmp = s.pop();
while (n.getSize()!=0&&n.peek()<tmp)
{
s.push(n.pop());
}
n.push(tmp);
}
return n;
}
示例14: Main
public static void Main()
{
Stack s = new Stack();
Console.Write("Stack is created\n");
s.push(10); s.push(3); s.push(11); s.push(7);
s.display();
int i = s.pop();
Console.Write("\nJust popped {0}", i);
s.display();
int[] search = { 2, 3 };
foreach(int cur in search)
{
if (s.isMember(cur))
{
Console.Write("\n{0} is in the stack", cur);
}
else
{
Console.Write("\n{0} is not in the stack", cur);
}
}
}
示例15: iterativeDF
public void iterativeDF(int s)
{
Stack S = new Stack();
id = 0;
for (int v = 1; v < V + 1; ++v)
{
visited[v] = 0;
}
S.push(s);
int prev = 0;
while (!S.isEmpty())
{
int v = S.pop();
if (visited[v] == 0)
{
visited[v] = ++id;
Console.WriteLine("Visited vertex {0} along edge {1} - {0}", v, prev);
Node cur = adj[v];
while (cur != z)
{
int u = cur.vert;
if (visited[u] == 0)
{
S.push(u);
}
prev = v;
cur = cur.next;
}
}
}
}