博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
stack.pop()方法_C.示例中的Stack.Pop()方法
阅读量:2529 次
发布时间:2019-05-11

本文共 2229 字,大约阅读时间需要 7 分钟。

stack.pop()方法

C#Stack.Pop()方法 (C# Stack.Pop() method)

Stack.Pop() method is used to remove an object from the top of the stack. The method removes and returns the object from the top.

Stack.Pop()方法用于从堆栈顶部删除对象。 该方法从顶部删除并返回对象。

Syntax:

句法:

Object Stack.Pop();

Parameters: None

参数:

Return value: Object – it returns the items to be removed from the top.

返回值: Object –返回从顶部删除的项目。

Example:

例:

declare and initialize a stack:    Stack stk = new Stack();    insertting elements:    stk.Push(100);    stk.Push(200);    stk.Push(300);    stk.Push(400);    stk.Push(500);    popping stack elements:    stk.Pop();    stk.Pop();    stk.Pop();        Output:    200 100

C#示例使用Stack.Pop()方法从堆栈中删除对象 (C# example to remove an object from the stack using Stack.Pop() method)

using System;using System.Text;using System.Collections;namespace Test{
class Program {
//function to print stack elements static void printStack(Stack s) {
foreach (Object obj in s) {
Console.Write(obj + " "); } Console.WriteLine(); } static void Main(string[] args) {
//declare and initialize a stack Stack stk = new Stack(); //insertting elements stk.Push(100); stk.Push(200); stk.Push(300); stk.Push(400); stk.Push(500); //printing stack elements Console.WriteLine("Stack elements before popping are..."); printStack(stk); //popping stack elements object item = 0; item = stk.Pop(); Console.WriteLine(item + " is popped"); item = stk.Pop(); Console.WriteLine(item + " is popped"); item = stk.Pop(); Console.WriteLine(item + " is popped"); //printing stack elements Console.WriteLine("Stack elements after popping are..."); printStack(stk); //hit ENTER to exit Console.ReadLine(); } }}

Output

输出量

Stack elements before popping are...500 400 300 200 100500 is popped400 is popped300 is poppedStack elements after popping are...200 100

Reference:

参考:

翻译自:

stack.pop()方法

转载地址:http://hrxzd.baihongyu.com/

你可能感兴趣的文章
在mvc3中使用ffmpeg对上传视频进行截图和转换格式
查看>>
python的字符串内建函数
查看>>
Spring - DI
查看>>
微软自己的官网介绍 SSL 参数相关
查看>>
Composite UI Application Block (CAB) 概念和术语
查看>>
64位MATLAB和C混合编程以及联合调试
查看>>
原生js大总结二
查看>>
PHP基础
查看>>
UVa 11488 超级前缀集合(Trie的应用)
查看>>
Django 翻译与 LANGUAGE_CODE
查看>>
[转]iOS教程:SQLite的创建数据库,表,插入查看数据
查看>>
【转载】OmniGraffle (一)从工具栏开始
查看>>
初识ionic
查看>>
java 中打印调用栈
查看>>
开发 笔记
查看>>
ajax跨域,携带cookie
查看>>
阶段3 2.Spring_01.Spring框架简介_03.spring概述
查看>>
阶段3 2.Spring_02.程序间耦合_1 编写jdbc的工程代码用于分析程序的耦合
查看>>
阶段3 2.Spring_01.Spring框架简介_04.spring发展历程
查看>>
阶段3 2.Spring_02.程序间耦合_3 程序的耦合和解耦的思路分析1
查看>>