1.57. C# Stack

发布时间 : 2025-10-25 13:34:31 UTC      

Page Views: 9 views

The Stack represents a collection of last-in, first-out objects. Use the stack when you need last-in-first-out access to items. When you add an item to the list called a push element, when you remove an item from the list, itis called a pop-up element.

1.57.1. Methods and properties of the Stack class #

The following table lists some common properties of Stack class:

Attribute

Description

Count

Gets the number of elements contained in the Stack.

The following table lists some common methods of Stack .

Serial number

Method name & description

1

Public virtual void Clear (); removes all elements from the Stack.

2

Public virtual bool Contains (object obj); determines whether an element is in Stack.

3

Public virtual object Peek (); returns the object at the top of the Stack without removing it.

4

Public virtual object Pop (); removes and returns the object at the top of the Stack.

5

Public virtual void Push (object obj); add an object to the top of the Stack.

6

Public virtual object [] ToArray (); copy Stack into a new array.

1.57.2. Example #

The following example demonstrates the use of Stack:

Example #

using System; using System.Collections; namespace CollectionsApplication { class Program { static void Main(string[] args) { Stack st = new Stack(); st.Push('A'); st.Push('M'); st.Push('G'); st.Push('W'); Console.WriteLine("Current stack: "); foreach (char c in st) { Console.Write(c + " "); } Console.WriteLine(); st.Push('V'); st.Push('H'); Console.WriteLine("The next poppable value in stack: {0}", st.Peek()); Console.WriteLine("Current stack: "); foreach (char c in st) { Console.Write(c + " "); } Console.WriteLine(); Console.WriteLine("Removing values "); st.Pop(); st.Pop(); st.Pop(); Console.WriteLine("Current stack: "); foreach (char c in st) { Console.Write(c + " "); } } } } 

When the above code is compiled and executed, it produces the following results:

Current stack: W G M A The next poppable value in stack: H Current stack: H V W G M A Removing values Current stack: G M A 
《地理信息系统原理、技术与方法》  97

最近几年来,地理信息系统无论是在理论上还是应用上都处在一个飞速发展的阶段。 GIS被应用于多个领域的建模和决策支持,如城市管理、区划、环境整治等等,地理信息成为信息时代重要的组成部分之一; “数字地球”概念的提出,更进一步推动了作为其技术支撑的GIS的发展。 与此同时,一些学者致力于相关的理论研究,如空间感知、空间数据误差、空间关系的形式化等等。 这恰好说明了地理信息系统作为应用技术和学科的两个方面,并且这两个方面构成了相互促进的发展过程。