STACKとは? わかりやすく解説

Weblio 辞書 > 辞書・百科事典 > デジタル大辞泉 > STACKの意味・解説 

スタック【stack】


スタック

【英】stack

スタックとは、データ構造一つであるリストの中で、特に挿入削除リスト先頭からしかできないのであるこのような構造は、LIFO後入れ先出し)と呼ばれる

スタックは、例で言えば机上積み上げられ本のような構造をしている。本は上に積み上げられていき、読みたい本は上から順に取っていかなければ取れないという点が、スタックと似ている

スタックは、情報処理さまざまな場面欠かせないデータ構造であるといえるプログラムサブルーチン実行後に呼び出し元に戻る仕組みには、スタックが使われるサブルーチン実行する前に、スタックに戻り先を積み上げPUSH)、サブルーチンが処理を終わると、戻り先、つまり次にプログラム実行する番地取り出すPOP)。文書編集操作の「やり直し」や「元にもどす」などもスタックを利用して実現されているのが一般的である。

情報処理のほかの用語一覧
アルゴリズム:  シーケンシャルサーチ  挿入ソート  ソート  スタック  2分木  2分探索木  2分探索法

Stack クラス

オブジェクト単純な後入れ先出し (LIFO) 非ジェネリック コレクション表します

名前空間: System.Collections
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

<SerializableAttribute> _
<ComVisibleAttribute(True)> _
Public Class Stack
    Implements ICollection, IEnumerable, ICloneable
[SerializableAttribute] 
[ComVisibleAttribute(true)] 
public class Stack : ICollection, IEnumerable,
 ICloneable
[SerializableAttribute] 
[ComVisibleAttribute(true)] 
public ref class Stack : ICollection, IEnumerable,
 ICloneable
/** @attribute SerializableAttribute() */ 
/** @attribute ComVisibleAttribute(true) */ 
public class Stack implements ICollection,
 IEnumerable, 
    ICloneable
SerializableAttribute 
ComVisibleAttribute(true) 
public class Stack implements ICollection,
 IEnumerable, 
    ICloneable
解説解説

このコレクションジェネリック バージョンについては、「System.Collections.Generic.Stack」を参照してください

Stack は、循環バッファとして実装されます

Stack容量は、Stack保持できる要素数になりますStack既定初期量は 10 です。Stack要素追加すると、必要に応じて、再割り当てによって容量自動的に増加します。

Countスタック容量よりも小さ場合Push は O(1) 操作なります新し要素格納するために容量増やす必要がある場合Push は O(n) 操作なります。ここで、nCount です。Pop は O(1) 操作です。

Stack は、null 参照 (Visual Basic では Nothing) を有効な値として受け取り要素重複許可します

使用例使用例

Stack作成して値を追加する方法と、その値を出力する方法の例を次に示します

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 obj As [Object]
        For Each obj In
  myCollection
            Console.Write("    {0}", obj)
        Next obj
        Console.WriteLine()
    End Sub 'PrintValues

End Class

' This code produces the following output.
'
' myStack
'     Count:     3
'     Values:    !    World    Hello
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 )  {
      foreach ( Object obj in myCollection
 )
         Console.Write( "    {0}", obj );
      Console.WriteLine();
   }

}


/* 
This code produces the following output.

myStack
    Count:    3
    Values:    !    World    Hello
*/ 

using namespace System;
using namespace System::Collections;
void PrintValues( IEnumerable^ myCollection );
int main()
{
   
   // Creates and initializes a new Stack.
   Stack^ myStack = gcnew 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 );
}

void PrintValues( IEnumerable^ myCollection )
{
   IEnumerator^ myEnum = myCollection->GetEnumerator();
   while ( myEnum->MoveNext() )
   {
      Object^ obj = safe_cast<Object^>(myEnum->Current);
      Console::Write( "    {0}", obj );
   }

   Console::WriteLine();
}

/* 
 This code produces the following output.
 
 myStack
     Count:    3
     Values:    !    World    Hello
 */
import System.*;
import System.Collections.*;

public class SamplesStack
{
    public static void main(String[]
 args)
    {
        // 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}", 
            System.Convert.ToString(myStack.get_Count()));
        Console.Write("\tValues:");
        PrintValues(myStack);
    } //main

    public static void PrintValues(IEnumerable
 myCollection)
    {
        IEnumerator objEnum = myCollection.GetEnumerator();

        while (objEnum.MoveNext()) {
            Console.Write("    {0}", objEnum.get_Current());
        }
        Console.WriteLine();
    } //PrintValues

} //SamplesStack

/* 
 This code produces the following output.
 
 myStack
     Count:    3
     Values:    !    World    Hello
 */
継承階層継承階層
System.Object
  System.Collections.Stack
     Microsoft.VisualC.SymbolTableStack
スレッド セーフスレッド セーフ
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
Stack メンバ
System.Collections 名前空間
System.Collections.Generic.Stack

Stack コンストラクタ ()

空で、既定初期量を備えた、Stack クラス新しインスタンス初期化します。

名前空間: System.Collections
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

解説解説
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

Stack コンストラクタ ()

メモ : このコンストラクタは、.NET Framework version 2.0新しく追加されたものです。

空で、既定初期量を備えた、Stack クラス新しインスタンス初期化します。

名前空間: System.Collections.Generic
アセンブリ: System (system.dll 内)
構文構文

解説解説
使用例使用例

このコンストラクタおよび Stack ジェネリック クラスいくつかのメソッド使用したコード例次に示します

このコード例では、既定容量文字列スタック作成しPush メソッド使用して 5 つ文字列スタックプッシュます。スタック要素列挙されますが、スタックの状態は変化しません。Pop メソッド使用して最初文字列スタックからポップます。Peek メソッド使用してスタック内の次の項目を調べてから、Pop メソッド使用してその項目をスタックからポップます。

ToArray メソッド使用して配列作成し、その配列スタック要素コピーしてから、IEnumerable を受け取る Stack コンストラクタ配列渡して要素順序反転したスタックコピー作成しますコピー要素表示されます。

スタックの 2 倍のサイズ配列作成されCopyTo メソッド使用して配列中央部で始まる配列要素コピーしますStack コンストラクタ再度使用して要素順序反転したスタックコピー作成しますその結果3 つの null 要素末尾配置されます。

Contains メソッド使用して文字列 "four" がスタック最初コピーにあることを示しますその後で、Clear メソッドコピークリアすると、Count プロパティによってスタックが空であることが示されます。

Imports System
Imports System.Collections.Generic

Module Example

    Sub Main

        Dim numbers As New
 Stack(Of String)
        numbers.Push("one")
        numbers.Push("two")
        numbers.Push("three")
        numbers.Push("four")
        numbers.Push("five")

        ' A stack can be enumerated without disturbing its contents.
        For Each number As
 String In numbers
            Console.WriteLine(number)
        Next

        Console.WriteLine(vbLf & "Popping '{0}'", numbers.Pop())
        Console.WriteLine("Peek at next item to pop: {0}",
 _
            numbers.Peek())    
        Console.WriteLine("Popping '{0}'", numbers.Pop())

        ' Create another stack, using the ToArray method and the
        ' constructor that accepts an IEnumerable(Of T). Note that
        ' the order of items on the new stack is reversed.
        Dim stack2 As New
 Stack(Of String)(numbers.ToArray())

        Console.WriteLine(vbLf & "Contents of the first copy:")
        For Each number As
 String In stack2
            Console.WriteLine(number)
        Next
        
        ' Create an array twice the size of the stack, compensating
        ' for the fact that Visual Basic allocates an extra array 
        ' element. Copy the elements of the stack, starting at the
        ' middle of the array. 
        Dim array2((numbers.Count * 2) - 1) As
 String
        numbers.CopyTo(array2, numbers.Count)
        
        ' Create a second stack, using the constructor that accepts
 an
        ' IEnumerable(Of T). The elements are reversed, with the null
        ' elements appearing at the end of the stack when enumerated.
        Dim stack3 As New
 Stack(Of String)(array2)

        Console.WriteLine(vbLf & _
            "Contents of the second copy, with duplicates and
 nulls:")
        For Each number As
 String In stack3
            Console.WriteLine(number)
        Next

        Console.WriteLine(vbLf & "stack2.Contains(""four"")
 = {0}", _
            stack2.Contains("four"))

        Console.WriteLine(vbLf & "stack2.Clear()")
        stack2.Clear()
        Console.WriteLine(vbLf & "stack2.Count = {0}",
 _
            stack2.Count)
    End Sub
End Module

' This code example produces the following output:
'
'five
'four
'three
'two
'one
'
'Popping 'five'
'Peek at next item to pop: four
'Popping 'four'
'
'Contents of the first copy:
'one
'two
'three
'
'Contents of the second copy, with duplicates and nulls:
'one
'two
'three
'
'
'
'
'stack2.Contains("four") = False
'
'stack2.Clear()
'
'stack2.Count = 0
using System;
using System.Collections.Generic;

class Example
{
    public static void Main()
    {
        Stack<string> numbers = new Stack<string>();
        numbers.Push("one");
        numbers.Push("two");
        numbers.Push("three");
        numbers.Push("four");
        numbers.Push("five");

        // A stack can be enumerated without disturbing its contents.
        foreach( string number in
 numbers )
        {
            Console.WriteLine(number);
        }

        Console.WriteLine("\nPopping '{0}'", numbers.Pop());
        Console.WriteLine("Peek at next item to destack: {0}", 
            numbers.Peek());
        Console.WriteLine("Popping '{0}'", numbers.Pop());

        // Create a copy of the stack, using the ToArray method and
 the
        // constructor that accepts an IEnumerable<T>.
        Stack<string> stack2 = new Stack<string>(numbers.ToArray());

        Console.WriteLine("\nContents of the first copy:");
        foreach( string number in
 stack2 )
        {
            Console.WriteLine(number);
        }
        
        // Create an array twice the size of the stack and copy the
        // elements of the stack, starting at the middle of the 
        // array. 
        string[] array2 = new string[numbers.Count
 * 2];
        numbers.CopyTo(array2, numbers.Count);
        
        // Create a second stack, using the constructor that accepts
 an
        // IEnumerable(Of T).
        Stack<string> stack3 = new Stack<string>(array2);

        Console.WriteLine("\nContents of the second copy, with duplicates and
 nulls:");
        foreach( string number in
 stack3 )
        {
            Console.WriteLine(number);
        }

        Console.WriteLine("\nstack2.Contains(\"four\") = {0}",
 
            stack2.Contains("four"));

        Console.WriteLine("\nstack2.Clear()");
        stack2.Clear();
        Console.WriteLine("\nstack2.Count = {0}", stack2.Count);
    }
}

/* This code example produces the following output:

five
four
three
two
one

Popping 'five'
Peek at next item to destack: four
Popping 'four'

Contents of the first copy:
one
two
three

Contents of the second copy, with duplicates and nulls:
one
two
three




stack2.Contains("four") = False

stack2.Clear()

stack2.Count = 0
 */
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

Stack コンストラクタ (Int32)

空で、指定した初期量または既定初期量のうち大きい方の初期量を備えたStack クラス新しインスタンス初期化します。

名前空間: System.Collections
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

Public Sub New ( _
    initialCapacity As Integer _
)
Dim initialCapacity As Integer

Dim instance As New Stack(initialCapacity)
public Stack (
    int initialCapacity
)
public:
Stack (
    int initialCapacity
)
public Stack (
    int initialCapacity
)
public function Stack (
    initialCapacity : int
)

パラメータ

initialCapacity

Stack が格納できる要素数の初期値

例外例外
例外種類条件

ArgumentOutOfRangeException

initialCapacity が 0 未満です。

解説解説
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

Stack コンストラクタ (ICollection)

指定したコレクションからコピーした要素格納しコピーされる要素の数と同じ初期量を備えた、Stack クラス新しインスタンス初期化します。

名前空間: System.Collections
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

Public Sub New ( _
    col As ICollection _
)
Dim col As ICollection

Dim instance As New Stack(col)
public Stack (
    ICollection col
)
public:
Stack (
    ICollection^ col
)
public Stack (
    ICollection col
)
public function Stack (
    col : ICollection
)

パラメータ

col

要素コピー元の ICollection。

例外例外
例外種類条件

ArgumentNullException

colnull 参照 (Visual Basic では Nothing) です。

解説解説
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

Stack コンストラクタ (ジェネリック IEnumerable)

メモ : このコンストラクタは、.NET Framework version 2.0新しく追加されたものです。

指定したコレクションからコピーした要素格納しコピーされる要素の数を格納できるだけの容量備えた、Stack クラス新しインスタンス初期化します。

名前空間: System.Collections.Generic
アセンブリ: System (system.dll 内)
構文構文

Public Sub New ( _
    collection As IEnumerable(Of T) _
)
Dim collection As IEnumerable(Of
 T)

Dim instance As New Stack(Of
 T)(collection)
public Stack (
    IEnumerable<T> collection
)
public:
Stack (
    IEnumerable<T>^ collection
)
public Stack (
    IEnumerable<T> collection
)
public function Stack (
    collection : IEnumerable<T>
)

パラメータ

collection

要素コピー元のコレクション

例外例外
例外種類条件

ArgumentNullException

collectionnull 参照 (Visual Basic では Nothing) です。

解説解説

Stack容量は、Stack保持できる要素数になりますStack要素追加すると、必要に応じて内部配列の再割り当てによって容量自動的に増加します。

コレクションサイズ推定できる場合は、初期量を指定すると、Stack要素追加するときに、サイズ変更操作何度も実行する必要がなくなります

容量を減らすには、TrimExcess を呼び出します。

要素は、コレクションの IEnumerator によって読み取られる順序と同じ順序で、Stackコピーされます。

このコンストラクタは O(n) 操作です。ここで、ncollection 内の要素数です。

使用例使用例

このコンストラクタおよび Stack ジェネリック クラスいくつかのメソッド使用したコード例次に示します

このコード例では、既定容量文字列スタック作成しPush メソッド使用して 5 つ文字列スタックプッシュます。スタック要素列挙されますが、スタックの状態は変化しません。Pop メソッド使用して最初文字列スタックからポップます。Peek メソッド使用してスタック内の次の項目を調べてから、Pop メソッド使用してその項目をスタックからポップます。

ToArray メソッド使用して配列作成し、その配列スタック要素コピーしてから、IEnumerable を受け取Stack コンストラクタ配列渡して要素順序反転したスタックコピー作成しますコピー要素表示されます。

スタックの 2 倍のサイズ配列作成されCopyTo メソッド使用して配列中央部で始まる配列要素コピーしますStack コンストラクタ再度使用して要素順序反転したスタックコピー作成しますその結果3 つの null 要素末尾配置されます。

Contains メソッド使用して文字列 "four" がスタック最初コピーにあることを示しますその後で、Clear メソッドコピークリアすると、Count プロパティによってスタックが空であることが示されます。

Imports System
Imports System.Collections.Generic

Module Example

    Sub Main

        Dim numbers As New
 Stack(Of String)
        numbers.Push("one")
        numbers.Push("two")
        numbers.Push("three")
        numbers.Push("four")
        numbers.Push("five")

        ' A stack can be enumerated without disturbing its contents.
        For Each number As
 String In numbers
            Console.WriteLine(number)
        Next

        Console.WriteLine(vbLf & "Popping '{0}'", numbers.Pop())
        Console.WriteLine("Peek at next item to pop: {0}",
 _
            numbers.Peek())    
        Console.WriteLine("Popping '{0}'", numbers.Pop())

        ' Create another stack, using the ToArray method and the
        ' constructor that accepts an IEnumerable(Of T). Note that
        ' the order of items on the new stack is reversed.
        Dim stack2 As New
 Stack(Of String)(numbers.ToArray())

        Console.WriteLine(vbLf & "Contents of the first copy:")
        For Each number As
 String In stack2
            Console.WriteLine(number)
        Next
        
        ' Create an array twice the size of the stack, compensating
        ' for the fact that Visual Basic allocates an extra array 
        ' element. Copy the elements of the stack, starting at the
        ' middle of the array. 
        Dim array2((numbers.Count * 2) - 1) As
 String
        numbers.CopyTo(array2, numbers.Count)
        
        ' Create a second stack, using the constructor that accepts
 an
        ' IEnumerable(Of T). The elements are reversed, with the null
        ' elements appearing at the end of the stack when enumerated.
        Dim stack3 As New
 Stack(Of String)(array2)

        Console.WriteLine(vbLf & _
            "Contents of the second copy, with duplicates and
 nulls:")
        For Each number As
 String In stack3
            Console.WriteLine(number)
        Next

        Console.WriteLine(vbLf & "stack2.Contains(""four"")
 = {0}", _
            stack2.Contains("four"))

        Console.WriteLine(vbLf & "stack2.Clear()")
        stack2.Clear()
        Console.WriteLine(vbLf & "stack2.Count = {0}",
 _
            stack2.Count)
    End Sub
End Module

' This code example produces the following output:
'
'five
'four
'three
'two
'one
'
'Popping 'five'
'Peek at next item to pop: four
'Popping 'four'
'
'Contents of the first copy:
'one
'two
'three
'
'Contents of the second copy, with duplicates and nulls:
'one
'two
'three
'
'
'
'
'stack2.Contains("four") = False
'
'stack2.Clear()
'
'stack2.Count = 0
using System;
using System.Collections.Generic;

class Example
{
    public static void Main()
    {
        Stack<string> numbers = new Stack<string>();
        numbers.Push("one");
        numbers.Push("two");
        numbers.Push("three");
        numbers.Push("four");
        numbers.Push("five");

        // A stack can be enumerated without disturbing its contents.
        foreach( string number in
 numbers )
        {
            Console.WriteLine(number);
        }

        Console.WriteLine("\nPopping '{0}'", numbers.Pop());
        Console.WriteLine("Peek at next item to destack: {0}", 
            numbers.Peek());
        Console.WriteLine("Popping '{0}'", numbers.Pop());

        // Create a copy of the stack, using the ToArray method and
 the
        // constructor that accepts an IEnumerable<T>.
        Stack<string> stack2 = new Stack<string>(numbers.ToArray());

        Console.WriteLine("\nContents of the first copy:");
        foreach( string number in
 stack2 )
        {
            Console.WriteLine(number);
        }
        
        // Create an array twice the size of the stack and copy the
        // elements of the stack, starting at the middle of the 
        // array. 
        string[] array2 = new string[numbers.Count
 * 2];
        numbers.CopyTo(array2, numbers.Count);
        
        // Create a second stack, using the constructor that accepts
 an
        // IEnumerable(Of T).
        Stack<string> stack3 = new Stack<string>(array2);

        Console.WriteLine("\nContents of the second copy, with duplicates and
 nulls:");
        foreach( string number in
 stack3 )
        {
            Console.WriteLine(number);
        }

        Console.WriteLine("\nstack2.Contains(\"four\") = {0}",
 
            stack2.Contains("four"));

        Console.WriteLine("\nstack2.Clear()");
        stack2.Clear();
        Console.WriteLine("\nstack2.Count = {0}", stack2.Count);
    }
}

/* This code example produces the following output:

five
four
three
two
one

Popping 'five'
Peek at next item to destack: four
Popping 'four'

Contents of the first copy:
one
two
three

Contents of the second copy, with duplicates and nulls:
one
two
three




stack2.Contains("four") = False

stack2.Clear()

stack2.Count = 0
 */
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

Stack コンストラクタ (Int32)

メモ : このコンストラクタは、.NET Framework version 2.0新しく追加されたものです。

空で、指定した初期量または既定初期量のうち大きい方の初期量を備えたStack クラス新しインスタンス初期化します。

名前空間: System.Collections.Generic
アセンブリ: System (system.dll 内)
構文構文

例外例外
例外種類条件

ArgumentOutOfRangeException

capacity が 0 未満です。

解説解説

Stack容量は、Stack保持できる要素数になりますStack要素追加すると、必要に応じて内部配列の再割り当てによって容量自動的に増加します。

コレクションサイズ推定できる場合は、初期量を指定すると、Stack要素追加するときに、サイズ変更操作何度も実行する必要がなくなります

容量を減らすには、TrimExcess を呼び出します。

このコンストラクタは O(n) 操作です。ここで、ncapacity です。

プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

Stack コンストラクタ


Stack コンストラクタ


Stack ジェネリック クラス

メモ : このクラスは、.NET Framework version 2.0新しく追加されたものです。

任意の同じ型のインスタンスの、可変サイズ後入れ先出し (LIFO) コレクション表します

名前空間: System.Collections.Generic
アセンブリ: System (system.dll 内)
構文構文

<SerializableAttribute> _
<ComVisibleAttribute(False)> _
Public Class Stack(Of T)
    Implements IEnumerable(Of T), ICollection,
 _
    IEnumerable
[SerializableAttribute] 
[ComVisibleAttribute(false)] 
public class Stack<T> : IEnumerable<T>,
 ICollection, 
    IEnumerable
[SerializableAttribute] 
[ComVisibleAttribute(false)] 
generic<typename T>
public ref class Stack : IEnumerable<T>,
 ICollection, 
    IEnumerable
J# では、ジェネリックな型およびメソッド使用できますが、新規に宣言することはできません。
JScript では、ジェネリックな型およびメソッド使用できません。

型パラメータ

T

スタック内の要素の型を指定します

解説解説

Stack は、配列として実装されます

Stack容量は、Stack保持できる要素数になります。この実装では、Stack既定初期量は 10 ですが、この既定値将来.NET Framework SDKバージョン変更される可能性ありますStack要素追加すると、必要に応じて内部配列の再割り当てによって容量自動的に増加します。容量を減らすには、TrimExcess を呼び出します。

Countスタック容量よりも小さ場合Push は O(1) 操作なります新し要素格納するために容量増やす必要がある場合Push は O(n) 操作なります。ここで、nCount です。Pop は O(1) 操作です。

Stack は、null 参照 (Visual Basic では Nothing) を参照型に対して有効な値として受け取り要素重複許可します

使用例使用例

Stack ジェネリック クラスいくつかのメソッド使用したコード例次に示します。このコード例では、既定容量文字列スタック作成しPush メソッド使用して 5 つ文字列スタックプッシュます。スタック要素列挙されますが、スタックの状態は変化しません。Pop メソッド使用して最初文字列スタックからポップます。Peek メソッド使用してスタック内の次の項目を調べてから、Pop メソッド使用してその項目をスタックからポップます。

ToArray メソッド使用して配列作成し、その配列スタック要素コピーしてから、IEnumerable を受け取る Stack コンストラクタ配列渡して要素順序反転したスタックコピー作成しますコピー要素表示されます。

スタックの 2 倍のサイズ配列作成されCopyTo メソッド使用して配列中央部で始まる配列要素コピーしますStack コンストラクタ再度使用して要素順序反転したスタックコピー作成しますその結果3 つの null 要素末尾配置されます。

Contains メソッド使用して文字列 "four" がスタック最初コピーにあることを示しますその後で、Clear メソッドコピークリアすると、Count プロパティによってスタックが空であることが示されます。

Imports System
Imports System.Collections.Generic

Module Example

    Sub Main

        Dim numbers As New
 Stack(Of String)
        numbers.Push("one")
        numbers.Push("two")
        numbers.Push("three")
        numbers.Push("four")
        numbers.Push("five")

        ' A stack can be enumerated without disturbing its contents.
        For Each number As
 String In numbers
            Console.WriteLine(number)
        Next

        Console.WriteLine(vbLf & "Popping '{0}'", numbers.Pop())
        Console.WriteLine("Peek at next item to pop: {0}",
 _
            numbers.Peek())    
        Console.WriteLine("Popping '{0}'", numbers.Pop())

        ' Create another stack, using the ToArray method and the
        ' constructor that accepts an IEnumerable(Of T). Note that
        ' the order of items on the new stack is reversed.
        Dim stack2 As New
 Stack(Of String)(numbers.ToArray())

        Console.WriteLine(vbLf & "Contents of the first copy:")
        For Each number As
 String In stack2
            Console.WriteLine(number)
        Next
        
        ' Create an array twice the size of the stack, compensating
        ' for the fact that Visual Basic allocates an extra array 
        ' element. Copy the elements of the stack, starting at the
        ' middle of the array. 
        Dim array2((numbers.Count * 2) - 1) As
 String
        numbers.CopyTo(array2, numbers.Count)
        
        ' Create a second stack, using the constructor that accepts
 an
        ' IEnumerable(Of T). The elements are reversed, with the null
        ' elements appearing at the end of the stack when enumerated.
        Dim stack3 As New
 Stack(Of String)(array2)

        Console.WriteLine(vbLf & _
            "Contents of the second copy, with duplicates and
 nulls:")
        For Each number As
 String In stack3
            Console.WriteLine(number)
        Next

        Console.WriteLine(vbLf & "stack2.Contains(""four"")
 = {0}", _
            stack2.Contains("four"))

        Console.WriteLine(vbLf & "stack2.Clear()")
        stack2.Clear()
        Console.WriteLine(vbLf & "stack2.Count = {0}",
 _
            stack2.Count)
    End Sub
End Module

' This code example produces the following output:
'
'five
'four
'three
'two
'one
'
'Popping 'five'
'Peek at next item to pop: four
'Popping 'four'
'
'Contents of the first copy:
'one
'two
'three
'
'Contents of the second copy, with duplicates and nulls:
'one
'two
'three
'
'
'
'
'stack2.Contains("four") = False
'
'stack2.Clear()
'
'stack2.Count = 0
using System;
using System.Collections.Generic;

class Example
{
    public static void Main()
    {
        Stack<string> numbers = new Stack<string>();
        numbers.Push("one");
        numbers.Push("two");
        numbers.Push("three");
        numbers.Push("four");
        numbers.Push("five");

        // A stack can be enumerated without disturbing its contents.
        foreach( string number in
 numbers )
        {
            Console.WriteLine(number);
        }

        Console.WriteLine("\nPopping '{0}'", numbers.Pop());
        Console.WriteLine("Peek at next item to destack: {0}", 
            numbers.Peek());
        Console.WriteLine("Popping '{0}'", numbers.Pop());

        // Create a copy of the stack, using the ToArray method and
 the
        // constructor that accepts an IEnumerable<T>.
        Stack<string> stack2 = new Stack<string>(numbers.ToArray());

        Console.WriteLine("\nContents of the first copy:");
        foreach( string number in
 stack2 )
        {
            Console.WriteLine(number);
        }
        
        // Create an array twice the size of the stack and copy the
        // elements of the stack, starting at the middle of the 
        // array. 
        string[] array2 = new string[numbers.Count
 * 2];
        numbers.CopyTo(array2, numbers.Count);
        
        // Create a second stack, using the constructor that accepts
 an
        // IEnumerable(Of T).
        Stack<string> stack3 = new Stack<string>(array2);

        Console.WriteLine("\nContents of the second copy, with duplicates and
 nulls:");
        foreach( string number in
 stack3 )
        {
            Console.WriteLine(number);
        }

        Console.WriteLine("\nstack2.Contains(\"four\") = {0}",
 
            stack2.Contains("four"));

        Console.WriteLine("\nstack2.Clear()");
        stack2.Clear();
        Console.WriteLine("\nstack2.Count = {0}", stack2.Count);
    }
}

/* This code example produces the following output:

five
four
three
two
one

Popping 'five'
Peek at next item to destack: four
Popping 'four'

Contents of the first copy:
one
two
three

Contents of the second copy, with duplicates and nulls:
one
two
three




stack2.Contains("four") = False

stack2.Clear()

stack2.Count = 0
 */
継承階層継承階層
System.Object
  System.Collections.Generic.Stack
スレッド セーフスレッド セーフ

この型の public static (Visual Basic では Shared) メンバは、スレッド セーフです。すべてのインスタンス メンバスレッド セーフになるかどうか保証されていません。

コレクション変更されない限りStack では、複数読み込み操作同時に発生して問題ありません。ただし、コレクション列挙処理は、本質的にスレッド セーフな処理ではありません。すべての列挙処理が終わるまでコレクションロックすることにより、列挙処理でのスレッド セーフ確保できますコレクション対し複数スレッドアクセスして読み取り書き込みを行うことができるようにするには、独自に同期化実装する必要があります

プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
Stack メンバ
System.Collections.Generic 名前空間

Stack プロパティ


パブリック プロパティパブリック プロパティ

  名前 説明
パブリック プロパティ SyncRoot Stack へのアクセス同期するために使用できるオブジェクト取得します
参照参照

関連項目

Stack クラス
System.Collections 名前空間
System.Collections.Generic.Stack

Stack プロパティ


パブリック プロパティパブリック プロパティ

  名前 説明
パブリック プロパティ Count Stack に格納されている要素の数を取得します
明示的インターフェイスの実装明示的インターフェイス実装
  名前 説明
インターフェイスの明示的な実装 System.Collections.ICollection.SyncRoot ICollection へのアクセス同期するために使用できるオブジェクト取得します
参照参照

関連項目

Stack ジェネリック クラス
System.Collections.Generic 名前空間

Stack メソッド


パブリック メソッドパブリック メソッド

( プロテクト メソッド参照)
  名前 説明
パブリック メソッド Clear Stack からすべてのオブジェクト削除します
パブリック メソッド Contains ある要素Stack 内に存在するかどうか判断します
パブリック メソッド CopyTo 既存1 次元ArrayStackコピーしますコピー操作は、配列指定したインデックスから始まります
パブリック メソッド Equals  オーバーロードされます2 つObject インスタンス等しかどうか判断します。 ( Object から継承されます。)
パブリック メソッド GetEnumerator Stack列挙子を返します
パブリック メソッド GetHashCode  特定の型のハッシュ関数として機能します。GetHashCode は、ハッシュ アルゴリズムや、ハッシュ テーブルのようなデータ構造での使用適してます。 ( Object から継承されます。)
パブリック メソッド GetType  現在のインスタンスType取得します。 ( Object から継承されます。)
パブリック メソッド Peek Stack先頭にあるオブジェクト削除せず返します
パブリック メソッド Pop Stack先頭にあるオブジェクト削除し返します
パブリック メソッド Push Stack先頭オブジェクト挿入します
パブリック メソッド ReferenceEquals  指定した複数Object インスタンス同一かどうか判断します。 ( Object から継承されます。)
パブリック メソッド ToArray Stack新し配列コピーします
パブリック メソッド ToString  現在の Object を表す String返します。 ( Object から継承されます。)
パブリック メソッド TrimExcess Stack 内にある実際要素数が現在の容量90% 未満場合は、容量をその数に設定します
プロテクト メソッドプロテクト メソッド
明示的インターフェイスの実装明示的インターフェイス実装
  名前 説明
インターフェイスの明示的な実装 System.Collections.Generic.IEnumerable<T>.GetEnumerator コレクション反復処理する列挙子を返します
インターフェイスの明示的な実装 System.Collections.ICollection.CopyTo ICollection の要素ArrayコピーしますArray特定のインデックスからコピー開始されます。
インターフェイスの明示的な実装 System.Collections.IEnumerable.GetEnumerator コレクション反復処理する列挙子を返します
参照参照

関連項目

Stack ジェネリック クラス
System.Collections.Generic 名前空間

Stack メソッド


パブリック メソッドパブリック メソッド

( プロテクト メソッド参照)
  名前 説明
パブリック メソッド Clear Stack からすべてのオブジェクト削除します
パブリック メソッド Clone Stack簡易コピー作成します
パブリック メソッド Contains ある要素Stack 内に存在するかどうか判断します
パブリック メソッド CopyTo 既存1 次元ArrayStackコピーしますコピー操作は、配列指定したインデックスから始まります
パブリック メソッド Equals  オーバーロードされます2 つObject インスタンス等しかどうか判断します。 ( Object から継承されます。)
パブリック メソッド GetEnumerator Stack の IEnumerator を返します
パブリック メソッド GetHashCode  特定の型のハッシュ関数として機能します。GetHashCode は、ハッシュ アルゴリズムや、ハッシュ テーブルのようなデータ構造での使用適してます。 ( Object から継承されます。)
パブリック メソッド GetType  現在のインスタンスType取得します。 ( Object から継承されます。)
パブリック メソッド Peek Stack先頭にあるオブジェクト削除せず返します
パブリック メソッド Pop Stack先頭にあるオブジェクト削除し返します
パブリック メソッド Push Stack先頭オブジェクト挿入します
パブリック メソッド ReferenceEquals  指定した複数Object インスタンス同一かどうか判断します。 ( Object から継承されます。)
パブリック メソッド Synchronized Stack 用の同期された (スレッド セーフな) ラッパー返します
パブリック メソッド ToArray Stack新し配列コピーします
パブリック メソッド ToString  現在の Object を表す String返します。 ( Object から継承されます。)
プロテクト メソッドプロテクト メソッド
参照参照

関連項目

Stack クラス
System.Collections 名前空間
System.Collections.Generic.Stack

Stack メンバ

任意の同じ型のインスタンスの、可変サイズ後入れ先出し (LIFO) コレクション表します

Stack ジェネリック型公開されるメンバを以下の表に示します


パブリック コンストラクタパブリック コンストラクタ
パブリック プロパティパブリック プロパティ
  名前 説明
パブリック プロパティ Count Stack格納されている要素の数を取得します
パブリック メソッドパブリック メソッド
( プロテクト メソッド参照)
  名前 説明
パブリック メソッド Clear Stack からすべてのオブジェクト削除します
パブリック メソッド Contains ある要素Stack 内に存在するかどうか判断します
パブリック メソッド CopyTo 既存1 次元ArrayStackコピーしますコピー操作は、配列指定したインデックスから始まります
パブリック メソッド Equals  オーバーロードされます2 つObject インスタンス等しかどうか判断します。 (Object から継承されます。)
パブリック メソッド GetEnumerator Stack列挙子を返します
パブリック メソッド GetHashCode  特定の型のハッシュ関数として機能します。GetHashCode は、ハッシュ アルゴリズムや、ハッシュ テーブルのようなデータ構造での使用適してます。 (Object から継承されます。)
パブリック メソッド GetType  現在のインスタンスType取得します。 (Object から継承されます。)
パブリック メソッド Peek Stack先頭にあるオブジェクト削除せず返します
パブリック メソッド Pop Stack先頭にあるオブジェクト削除し返します
パブリック メソッド Push Stack先頭オブジェクト挿入します
パブリック メソッド ReferenceEquals  指定した複数Object インスタンス同一かどうか判断します。 (Object から継承されます。)
パブリック メソッド ToArray Stack新し配列コピーします
パブリック メソッド ToString  現在の Object を表す String返します。 (Object から継承されます。)
パブリック メソッド TrimExcess Stack 内にある実際要素数が現在の容量90% 未満場合は、容量をその数に設定します
プロテクト メソッドプロテクト メソッド
明示的インターフェイスの実装明示的インターフェイス実装
  名前 説明
インターフェイスの明示的な実装 System.Collections.Generic.IEnumerable<T>.GetEnumerator コレクション反復処理する列挙子を返します
インターフェイスの明示的な実装 System.Collections.ICollection.CopyTo ICollection の要素ArrayコピーしますArray特定のインデックスからコピー開始されます。
インターフェイスの明示的な実装 System.Collections.IEnumerable.GetEnumerator コレクション反復処理する列挙子を返します
インターフェイスの明示的な実装 System.Collections.ICollection.SyncRoot ICollection へのアクセス同期するために使用できるオブジェクト取得します
参照参照

関連項目

Stack ジェネリック クラス
System.Collections.Generic 名前空間

Stack メンバ

オブジェクト単純な後入れ先出し (LIFO) 非ジェネリック コレクション表します

Stack データ型公開されるメンバを以下の表に示します


パブリック コンストラクタパブリック コンストラクタ
パブリック プロパティパブリック プロパティ
  名前 説明
パブリック プロパティ SyncRoot Stack へのアクセス同期するために使用できるオブジェクト取得します
パブリック メソッドパブリック メソッド
( プロテクト メソッド参照)
  名前 説明
パブリック メソッド Clear Stack からすべてのオブジェクト削除します
パブリック メソッド Clone Stack簡易コピー作成します
パブリック メソッド Contains ある要素Stack 内に存在するかどうか判断します
パブリック メソッド CopyTo 既存1 次元ArrayStackコピーしますコピー操作は、配列指定したインデックスから始まります
パブリック メソッド Equals  オーバーロードされます2 つObject インスタンス等しかどうか判断します。 (Object から継承されます。)
パブリック メソッド GetEnumerator Stack の IEnumerator を返します
パブリック メソッド GetHashCode  特定の型のハッシュ関数として機能します。GetHashCode は、ハッシュ アルゴリズムや、ハッシュ テーブルのようなデータ構造での使用適してます。 (Object から継承されます。)
パブリック メソッド GetType  現在のインスタンスType取得します。 (Object から継承されます。)
パブリック メソッド Peek Stack先頭にあるオブジェクト削除せず返します
パブリック メソッド Pop Stack先頭にあるオブジェクト削除し返します
パブリック メソッド Push Stack先頭オブジェクト挿入します
パブリック メソッド ReferenceEquals  指定した複数Object インスタンス同一かどうか判断します。 (Object から継承されます。)
パブリック メソッド Synchronized Stack 用の同期された (スレッド セーフな) ラッパー返します
パブリック メソッド ToArray Stack新し配列コピーします
パブリック メソッド ToString  現在の Object を表す String返します。 (Object から継承されます。)
プロテクト メソッドプロテクト メソッド
参照参照

関連項目

Stack クラス
System.Collections 名前空間
System.Collections.Generic.Stack

Stack

ポーカーテーブルにおいて、自分もっている金額 (即ち自分前にあるstack of chipsチップの山))。時に複数形使われるshort stack(ショートスタック)も参考のこと。
stack(スタック)は、特定の数のチップを指すこともある。ほとんどのchip racks(チップラック)は、20を1スタックの形で収容するタイプのものであるプレーヤー中には自分チップ好み大きさスタックにして並べている人も多い。私(Dan)は、10チップスタックが好きであるが、20とか30チップスタックにしている人が多いようである。

I was doing well earlier, but my stacks have been dwindling.
最初好調だったんだけど、チップの量はほとんど変化せずそのままだねえ)。

Stack

名前 スタック

スタック (曖昧さ回避)

(STACK から転送)

出典: フリー百科事典『ウィキペディア(Wikipedia)』 (2023/09/24 03:25 UTC 版)

スタックスタッキング

stack

stuck

脚注

関連項目


  1. ^ stuck”. weblio. 2023年1月23日閲覧。

stack

出典: フリー百科事典『ウィキペディア(Wikipedia)』 (2019/04/29 13:43 UTC 版)

Standard Template Library」の記事における「stack」の解説

スタック。(FILO; First In, Last Out)

※この「stack」の解説は、「Standard Template Library」の解説の一部です。
「stack」を含む「Standard Template Library」の記事については、「Standard Template Library」の概要を参照ください。


stack

出典: フリー百科事典『ウィキペディア(Wikipedia)』 (2020/12/28 07:58 UTC 版)

スタック (曖昧さ回避)」の記事における「stack」の解説

積み重ね山積みスタック - コンピュータデータ構造一種。特に、コールスタック有限会社スタック - ゲームメーカー。 π-スタック - 有機分子で、2つ芳香環重なること。 スタック (数学)(英語版) - スキーム代数的空間英語版)の一般化スポーツスタッキングでの用語。 煙突集合体複数アンテナを、垂直や水平に一定間隔置いて配置して出力合流させること。 プロトコル・スタック - コンピュータネットワーク通信プロトコルスイートソフトウェア実装HyperCard記述されたハイパーテキストデータの呼称カード集合体から)。 アルティメットでのオフェンスポジショニングウォー・シミュレーションゲームなどで、複数の駒が同一升目にある状態。駒を積み重ねることから。 時系列データ一定データ数ずつまたは一定データ周期加算すること。「移動平均」を参照 Adobe Photoshop Lightroomで、1つサムネイル複数写真登録すること。 英語圏の姓。リー・スタック(英語版) (Sir Lee Oliver Fitzmaurice Stack) - イギリス軍人ロバート・スタックRobert Stack)- アメリカの俳優声優グラハム・スタックGraham Stack)- イングランドサッカー選手Stack (Haskell)英語版) - Haskellパッケージ管理ツール

※この「stack」の解説は、「スタック (曖昧さ回避)」の解説の一部です。
「stack」を含む「スタック (曖昧さ回避)」の記事については、「スタック (曖昧さ回避)」の概要を参照ください。

ウィキペディア小見出し辞書の「STACK」の項目はプログラムで機械的に意味や本文を生成しているため、不適切な項目が含まれていることもあります。ご了承くださいませ。 お問い合わせ


英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

「STACK」の関連用語

STACKのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



STACKのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
デジタル大辞泉デジタル大辞泉
(C)Shogakukan Inc.
株式会社 小学館
IT用語辞典バイナリIT用語辞典バイナリ
Copyright © 2005-2024 Weblio 辞書 IT用語辞典バイナリさくいん。 この記事は、IT用語辞典バイナリスタックの記事を利用しております。
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2024 Microsoft.All rights reserved.
日本ポーカープレーヤーズ協会日本ポーカープレーヤーズ協会
日本ポーカープレーヤーズ協会 All Rights Reserved
日外アソシエーツ株式会社日外アソシエーツ株式会社
Copyright (C) 1994- Nichigai Associates, Inc., All rights reserved.
ウィキペディアウィキペディア
All text is available under the terms of the GNU Free Documentation License.
この記事は、ウィキペディアのスタック (曖昧さ回避) (改訂履歴)の記事を複製、再配布したものにあたり、GNU Free Documentation Licenseというライセンスの下で提供されています。 Weblio辞書に掲載されているウィキペディアの記事も、全てGNU Free Documentation Licenseの元に提供されております。
ウィキペディアウィキペディア
Text is available under GNU Free Documentation License (GFDL).
Weblio辞書に掲載されている「ウィキペディア小見出し辞書」の記事は、WikipediaのStandard Template Library (改訂履歴)、スタック (曖昧さ回避) (改訂履歴)の記事を複製、再配布したものにあたり、GNU Free Documentation Licenseというライセンスの下で提供されています。

©2024 GRAS Group, Inc.RSS