菜鸟跪求,高分问题:初学c#,怎么用它坐一个栈的算法!十分感谢~~~

aoran98 2004-10-30 02:39:53
初学c#,怎么用它坐一个栈的算法!十分感谢~~~
请大哥门指点~~~~~`
...全文
97 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
hawk234 2004-10-30
  • 打赏
  • 举报
回复
帮你顶
xiaoslong 2004-10-30
  • 打赏
  • 举报
回复
帮你顶
bebetoztx29 2004-10-30
  • 打赏
  • 举报
回复
help !!!
http://community.csdn.net/Expert/topic/3506/3506138.xml?temp=.2720148
brightheroes 2004-10-30
  • 打赏
  • 举报
回复
@楼主

System.Stack
现成的,为什么不用?
aoran98 2004-10-30
  • 打赏
  • 举报
回复
具体就是用c#语言写一个栈的程序,包括栈的的构造,插入,删除等~!
zhy0101 2004-10-30
  • 打赏
  • 举报
回复
public Stack
{
private int size;
private int top;
private int[] stack;

public Stack(int s)
{
size = s;
stack = new int[size];
top = -1;
}

public void Push(int item)
{
if(!IsFull())
stack[++top] = item;
}

public int Pop()
{
if(!IsEmpty())
return stack[top--];
}

public bool IsEmpty()
{
return top == -1;
}

public bool IsFull()
{
return top == size-1;
}
}
seamansam 2004-10-30
  • 打赏
  • 举报
回复
数据结构和语言关系不大,了解栈的概念就行了
brightheroes 2004-10-30
  • 打赏
  • 举报
回复
.NET Framework 类库

Stack 类 全部显示
表示对象的简单的后进先出集合。

有关此类型所有成员的列表,请参阅 Stack 成员。

System.Object
System.Collections.Stack

[Visual Basic]
<Serializable>
Public Class Stack
Implements ICollection, IEnumerable, ICloneable

[C#]
[Serializable]
public class Stack : ICollection, IEnumerable, ICloneable

[C++]
[Serializable]
public __gc class Stack : public ICollection, IEnumerable,
ICloneable

[JScript]
public
Serializable
class Stack implements ICollection, IEnumerable, ICloneable

线程安全
此类型的公共静态(在 Visual Basic 中为 Shared)成员对于多线程操作是安全的。不能保证实例成员是线程安全的。

若要保证 Stack 的线程安全,则必须通过由 Synchronized 方法返回的包装来执行所有操作。

通过集合枚举在本质上不是一个线程安全的过程。甚至在对集合进行同步处理时,其他线程仍可以修改该集合,这会导致枚举数引发异常。若要在枚举过程中保证线程安全,可以在整个枚举过程中锁定集合,或者捕捉由于其他线程进行的更改而引发的异常。

备注
将 Stack 实现为循环缓冲区。

如果 Count 小于堆栈的容量,则 Push 为 O(1) 操作。如果需要增加容量以容纳新元素,则 Push 成为 O(n) 操作,其中 n 为 Count。Pop 为 O(1) 操作。

Stack 接受空引用(Visual Basic 中为 Nothing)作为有效值并且允许重复的元素。

示例
[Visual Basic, C#, C++] 下列示例说明如何创建 Stack 并向其添加值,以及如何打印出其值。

[Visual Basic]
Imports System
Imports System.Collections
Imports Microsoft.VisualBasic

Public Class SamplesStack

Public Shared Sub Main()

' Creates and initializes a new Stack.
Dim myStack As New Stack()
myStack.Push("Hello")
myStack.Push("World")
myStack.Push("!")

' Displays the properties and values of the Stack.
Console.WriteLine("myStack")
Console.WriteLine(ControlChars.Tab & "Count: {0}", myStack.Count)
Console.Write(ControlChars.Tab & "Values:")
PrintValues(myStack)
End Sub

Public Shared Sub PrintValues(myCollection As IEnumerable)
Dim myEnumerator As System.Collections.IEnumerator = _
myCollection.GetEnumerator()
While myEnumerator.MoveNext()
Console.Write(ControlChars.Tab & "{0}", myEnumerator.Current)
End While
Console.WriteLine()
End Sub
End Class

' This code produces the following output.
'
' myStack
' Count: 3
' Values: ! World Hello

[C#]
using System;
using System.Collections;
public class SamplesStack {

public static void Main() {

// Creates and initializes a new Stack.
Stack myStack = new Stack();
myStack.Push("Hello");
myStack.Push("World");
myStack.Push("!");

// Displays the properties and values of the Stack.
Console.WriteLine( "myStack" );
Console.WriteLine( "\tCount: {0}", myStack.Count );
Console.Write( "\tValues:" );
PrintValues( myStack );
}


public static void PrintValues( IEnumerable myCollection ) {
System.Collections.IEnumerator myEnumerator = myCollection.GetEnumerator();
while ( myEnumerator.MoveNext() )
Console.Write( "\t{0}", myEnumerator.Current );
Console.WriteLine();
}
}
/*
This code produces the following output.

myStack
Count: 3
Values: ! World Hello
*/
ajqc 2004-10-30
  • 打赏
  • 举报
回复
"坐一个栈的算法"--实在不能理解你想问什么
brightheroes 2004-10-30
  • 打赏
  • 举报
回复
Stack
不是已经有了现成的了吗?
trh 2004-10-30
  • 打赏
  • 举报
回复
什么栈的算法,说明白点
aoran98 2004-10-30
  • 打赏
  • 举报
回复
有大哥帮帮忙嘛???

110,534

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧