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

queue

別表記:キュー

「queue」とは、行列・順番待ちを記載するリスト・行列に並ぶなどのことを意味する英語表現である。

「queue」とは・「queue」の意味

「queue」とは、「行列・順番待ちを記載するリスト」という名詞や「行列に並ぶ」という動詞の意味を持つ英単語である。「行列」といった意味はイギリス英語圏で使われる表現で、アメリカ英語圏では「line」を使うため、「queue」を用いても伝わらないことも珍しくない。例えば「ここで並んでお待ちください」と言う場合、イギリス英語圏では「Please wait in queue here.」となるが、アメリカ英語圏では「Please wait in line here.」と表現が異なってくる可能性がある。

IT用語としての「queue(待ち行列)」はデータ構造名として用いられている。「データ構造」とはデータを格納し、任意のタイミングでデータを取り出すことのできる器のことを意味する。「queue」においては、「先に入れたデータを、順番に取り出す」という構造になっている。そのデータの動きから「First-In First-OUT(FIFO)方式」とも呼ばれる。また、この「queue(キュー)」を用いて要素を管理することを「queuing(キューイング)」と言う。

なお、同音異義語として「que」があるが、これは「Quebec(カナダのケベック州)」の略称である。

「queue」の複数形

「queue」の複数形は「queues」である。

「queue」のスラングとしての意味

「queue」の一般的なスラングは特にないが、ネット・ゲーム用語として「対戦相手とのマッチング待機中」を示す際に「queue」が使われており、「Q」や「que」と略されることもある。また「solo queue(solo Q)」は「単独で参加登録をしてマッチング待機中」といった意味を持つ。更に、WEBログサービス「Tumblr(タンブラー)」において、「queue」とタグ付けをされることがある。これは、Tumblrが提供する「Queued post」という機能を利用して、予約投稿・自動投稿をした場合など付与されるタグである。

「queue」の発音・読み方

「queue」の発音記号は「kjuː」であり、カタカナ読みすると「キュー」となる。

「queue」の活用変化一覧

「queue」は、三人称単数現在形「queues」、現在分詞「queueing」あるいは「queuing」、過去形・過去分詞形「queued」と変化する。

「queue」の語源・由来

「queue」は、「尻尾」を意味するフランス語「queue」から転じたものであるとされる。

「queue」の覚え方

「queue」の覚え方としては、「9(キュー)人が列を作る」や「9(キュー)人の行列」といった語呂合わせがある。

「queue」を含む英熟語・英語表現

「queue up」とは


「queue up」とは、「列を作る、列に並ぶ、並んで立つ」といった意味を持つ英語表現である。「queue up for A」となると、「列に並んでAを待つ」という意味になる。

「in queue」とは


「in queue」とは、ゲーム用語であり、「対戦相手とのオンラインでのマッチングを待っている状態」を意味する言葉である。英語の文法としては誤りであり、本来は「in the queue」や「in a queue」が適切な表現となる。なお、「in Q」と省略することも多い。

「queue」を含む用語の解説

「queue(python)」とは


「queue(python)」とはプログラミング言語「python」の標準ライブラリに含まれているモジュール名である。IT用語における「queue」はデータ構造の一つであり、「先入先出キュー(FIFO)」のことを意味するが、pythonにおけるqueueモジュールにおいては、「先入先出キュー(FIFO)」だけでなく、「後入先出キュー(LIFO)」および「優先順位付きキュー」の三種類を含んでいる。

「queue」の使い方・例文

「queue」は一般的には「列」あるいは「列に並ぶ」という意味で用いられる。例文としては、「We waited in queue for an hour.(私たちは列に並んで一時間も待ちました)」や「There is a long queue waiting outside the shop.(店舗の外には長い行列ができている)」といった表現となる。また、「queue」に「jump」を追加することで「列に横から割り込む」という表現が可能となる。例えば「The woman jumped the queue.(その女性は割り込みをした)」、「Hey, no queue-jumping!(おい、割り込みするな!)」といった使い方ができる。

IT用語として用いる場合は、「Does the queue contain the data?(キューにはデータが含まれますか?)」や「Returns a queue task to active state.(キュータスクをアクティブに戻す)」、「There has been an error queuing your print job.(印刷ジョブをキューに登録する時、エラーになった)」などと使うことができる。

キュー【Q/q】

読み方:きゅー

1 英語のアルファベットの第17字。

2 〈Q〉《quality factor》電気回路における共振の鋭さを表す値。

3 〈Q〉大きなエネルギーの単位。1Q=2.52×1017kcalで、石炭約360億トンを燃やしたときの熱量に相当。

4 〈Q〉《question》疑問、質問、問題の略号。「―アンドA」

5 〈Q〉《queen》チェス・トランプで、クイーンの記号。

6 〈Q〉《quarter》四半期決算での、1つの期。

7 《「級(きゅう)」の音から》写真植字の級数を表す俗な略号。

8 〈q〉《(フランス)queue》染色体の長腕を表す記号。12qは12番染色体の長腕を意味する。


キュー【queue】


Queue キュー

外部からかかってきたすべてのインバウンドコールをACDの機能により一旦保留すること。着信コールを順番に手のあいたTSRに次々と接続できる。FIFO(First‐In/First-Out)という記憶方式により、先にかかった電話から順番に分配する。

Queue クラス

オブジェクトの先入れ先出しコレクションを表します。

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

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

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

Imports System
Imports System.Collections

Public Class SamplesQueue

    Public Shared Sub Main()

        ' Creates and initializes a new Queue.
        Dim myQ As New Queue()
        myQ.Enqueue("Hello")
        myQ.Enqueue("World")
        myQ.Enqueue("!")

        ' Displays the properties and values of the Queue.
        Console.WriteLine("myQ")
        Console.WriteLine("    Count:    {0}", myQ.Count)
        Console.Write("    Values:")
        PrintValues(myQ)

    End Sub 'Main

    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 'SamplesQueue


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

 using System;
 using System.Collections;
 public class SamplesQueue  {
 
    public static void Main()
  {
 
       // Creates and initializes a new Queue.
       Queue myQ = new Queue();
       myQ.Enqueue("Hello");
       myQ.Enqueue("World");
       myQ.Enqueue("!");
 
       // Displays the properties and values of the Queue.
       Console.WriteLine( "myQ" );
       Console.WriteLine( "\tCount:    {0}", myQ.Count );
       Console.Write( "\tValues:" );
       PrintValues( myQ );
    }
 
 
    public static void PrintValues(
 IEnumerable myCollection )  {
       foreach ( Object obj in myCollection
 )
          Console.Write( "    {0}", obj );
       Console.WriteLine();
    }
 }
 /* 
 This code produces the following output.
 
 myQ
     Count:    3
     Values:    Hello    World    !
*/ 
using namespace System;
using namespace System::Collections;
void PrintValues( IEnumerable^ myCollection );
int main()
{
   
   // Creates and initializes a new Queue.
   Queue^ myQ = gcnew Queue;
   myQ->Enqueue( "Hello" );
   myQ->Enqueue( "World" );
   myQ->Enqueue( "!" );
   
   // Displays the properties and values of the Queue.
   Console::WriteLine( "myQ" );
   Console::WriteLine( "\tCount:    {0}", myQ->Count );
   Console::Write( "\tValues:" );
   PrintValues( myQ );
}

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.
 
 myQ
     Count:    3
     Values:    Hello    World    !
*/
import System.*;
import System.Collections.*;

public class SamplesQueue
{
    public static void main(String[]
 args)
    {
        // Creates and initializes a new Queue.
        Queue myQ = new Queue();
        myQ.Enqueue("Hello");
        myQ.Enqueue("World");
        myQ.Enqueue("!");

        // Displays the properties and values of the Queue.
        Console.WriteLine("myQ");
        Console.WriteLine(
            "\tCount:    {0}",System.Convert.ToString(myQ.get_Count()));
        Console.Write("\tValues:");
        PrintValues(myQ);
    } //main

    public static void PrintValues(IEnumerable
 myCollection)
    {
        IEnumerator enumerator = myCollection.GetEnumerator();
        while(enumerator.MoveNext()) {
            Object obj = enumerator.get_Current();
            Console.Write("    {0}", obj);
        }
        Console.WriteLine();
    } //PrintValues
} //SamplesQueue

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

Queue コンストラクタ ()

空で、既定の初期量を備え、既定の増加率を使用する、Queue クラスの新しいインスタンスを初期化します。

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

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

Queue コンストラクタ ()

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

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

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

解説解説
使用例使用例

このコンストラクタおよび Queue ジェネリック クラスのその他いくつかのメソッドを使用したコード例を次に示します。このコード例では、既定の容量で文字列のキューを作成し、Enqueue メソッドを使用して 5 つの文字列をキューに置きます。キューの要素は列挙されますが、キューの状態は変化しません。Dequeue メソッドを使用して、最初の文字列をキューから取り出します。Peek メソッドを使用してキュー内の次の項目を調べてから、Dequeue メソッドを使用してキューから取り出します。

ToArray メソッドを使用して配列を作成し、その配列にキュー要素をコピーしてから、IEnumerable を受け取る Queue コンストラクタに配列を渡してキューのコピーを作成します。コピーの要素が表示されます。

キューの 2 倍のサイズの配列が作成され、CopyTo メソッドを使用して配列の中央部で始まる配列要素をコピーします。Queue コンストラクタを再度使用して、先頭に 3 つの null 要素を含むキューの 2 つ目のコピーを作成します。

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

Imports System
Imports System.Collections.Generic

Module Example

    Sub Main

        Dim numbers As New
 Queue(Of String)
        numbers.Enqueue("one")
        numbers.Enqueue("two")
        numbers.Enqueue("three")
        numbers.Enqueue("four")
        numbers.Enqueue("five")

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

        Console.WriteLine(vbLf & "Dequeuing '{0}'", numbers.Dequeue())
        Console.WriteLine("Peek at next item to dequeue: {0}",
 _
            numbers.Peek())    
        Console.WriteLine("Dequeuing '{0}'", numbers.Dequeue())

        ' Create a copy of the queue, using the ToArray method and the
        ' constructor that accepts an IEnumerable(Of T).
        Dim queueCopy As New
 Queue(Of String)(numbers.ToArray())

        Console.WriteLine(vbLf & "Contents of the first copy:")
        For Each number As
 String In queueCopy
            Console.WriteLine(number)
        Next
        
        ' Create an array twice the size of the queue, compensating
        ' for the fact that Visual Basic allocates an extra array 
        ' element. Copy the elements of the queue, starting at the
        ' middle of the array. 
        Dim array2((numbers.Count * 2) - 1) As
 String
        numbers.CopyTo(array2, numbers.Count)
        
        ' Create a second queue, using the constructor that accepts
 an
        ' IEnumerable(Of T).
        Dim queueCopy2 As New
 Queue(Of String)(array2)

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

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

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

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

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

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

        Console.WriteLine("\nDequeuing '{0}'", numbers.Dequeue());
        Console.WriteLine("Peek at next item to dequeue: {0}", 
            numbers.Peek());
        Console.WriteLine("Dequeuing '{0}'", numbers.Dequeue());

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

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

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

        Console.WriteLine("\nqueueCopy.Contains(\"four\") = {0}",
 
            queueCopy.Contains("four"));

        Console.WriteLine("\nqueueCopy.Clear()");
        queueCopy.Clear();
        Console.WriteLine("\nqueueCopy.Count = {0}", queueCopy.Count);
    }
}

/* This code example produces the following output:

one
two
three
four
five

Dequeuing 'one'
Peek at next item to dequeue: two
Dequeuing 'two'

Contents of the copy:
three
four
five

Contents of the second copy, with duplicates and nulls:



three
four
five

queueCopy.Contains("four") = True

queueCopy.Clear()

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

Queue コンストラクタ (Int32, Single)

空で、指定した初期量を備え、指定した増加率を使用する、Queue クラスの新しいインスタンスを初期化します。

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

Public Sub New ( _
    capacity As Integer, _
    growFactor As Single _
)
Dim capacity As Integer
Dim growFactor As Single

Dim instance As New Queue(capacity,
 growFactor)
public Queue (
    int capacity,
    float growFactor
)
public:
Queue (
    int capacity, 
    float growFactor
)
public Queue (
    int capacity, 
    float growFactor
)
public function Queue (
    capacity : int, 
    growFactor : float
)

パラメータ

capacity

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

growFactor

Queue の容量を拡張するときに使用する係数。

例外例外
例外の種類条件

ArgumentOutOfRangeException

capacity が 0 未満です。

または

growFactor が 1.0 未満であるか、10.0 を超えています。

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

Queue コンストラクタ (Int32)

空で、指定した初期量を備え、既定の増加率を使用する、Queue クラスの新しいインスタンスを初期化します。

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

例外例外
例外の種類条件

ArgumentOutOfRangeException

capacity が 0 未満です。

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

Queue コンストラクタ (Int32)

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

空で、指定した初期量を備えた、Queue クラスの新しいインスタンスを初期化します。

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

例外例外
例外の種類条件

ArgumentOutOfRangeException

capacity が 0 未満です。

解説解説

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

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

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

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

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

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

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

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

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

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

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

パラメータ

collection

新しい Queue に要素がコピーされたコレクション。

例外例外
例外の種類条件

ArgumentNullException

collection が null 参照 (Visual Basic では Nothing) です。

解説解説

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

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

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

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

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

使用例使用例

このコンストラクタおよび Queue ジェネリック クラスのその他いくつかのメソッドを使用したコード例を次に示します。このコード例では、既定の容量で文字列のキューを作成し、Enqueue メソッドを使用して 5 つの文字列をキューに置きます。キューの要素は列挙されますが、キューの状態は変化しません。Dequeue メソッドを使用して、最初の文字列をキューから取り出します。Peek メソッドを使用してキュー内の次の項目を調べてから、Dequeue メソッドを使用してキューから取り出します。

ToArray メソッドを使用して配列を作成し、その配列にキュー要素をコピーしてから、IEnumerable を受け取る Queue コンストラクタに配列を渡してキューのコピーを作成します。コピーの要素が表示されます。

キューの 2 倍のサイズの配列が作成され、CopyTo メソッドを使用して配列の中央部で始まる配列要素をコピーします。Queue コンストラクタを再度使用して、先頭に 3 つの null 要素を含むキューの 2 つ目のコピーを作成します。

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

Imports System
Imports System.Collections.Generic

Module Example

    Sub Main

        Dim numbers As New
 Queue(Of String)
        numbers.Enqueue("one")
        numbers.Enqueue("two")
        numbers.Enqueue("three")
        numbers.Enqueue("four")
        numbers.Enqueue("five")

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

        Console.WriteLine(vbLf & "Dequeuing '{0}'", numbers.Dequeue())
        Console.WriteLine("Peek at next item to dequeue: {0}",
 _
            numbers.Peek())    
        Console.WriteLine("Dequeuing '{0}'", numbers.Dequeue())

        ' Create a copy of the queue, using the ToArray method and the
        ' constructor that accepts an IEnumerable(Of T).
        Dim queueCopy As New
 Queue(Of String)(numbers.ToArray())

        Console.WriteLine(vbLf & "Contents of the first copy:")
        For Each number As
 String In queueCopy
            Console.WriteLine(number)
        Next
        
        ' Create an array twice the size of the queue, compensating
        ' for the fact that Visual Basic allocates an extra array 
        ' element. Copy the elements of the queue, starting at the
        ' middle of the array. 
        Dim array2((numbers.Count * 2) - 1) As
 String
        numbers.CopyTo(array2, numbers.Count)
        
        ' Create a second queue, using the constructor that accepts
 an
        ' IEnumerable(Of T).
        Dim queueCopy2 As New
 Queue(Of String)(array2)

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

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

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

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

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

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

        Console.WriteLine("\nDequeuing '{0}'", numbers.Dequeue());
        Console.WriteLine("Peek at next item to dequeue: {0}", 
            numbers.Peek());
        Console.WriteLine("Dequeuing '{0}'", numbers.Dequeue());

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

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

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

        Console.WriteLine("\nqueueCopy.Contains(\"four\") = {0}",
 
            queueCopy.Contains("four"));

        Console.WriteLine("\nqueueCopy.Clear()");
        queueCopy.Clear();
        Console.WriteLine("\nqueueCopy.Count = {0}", queueCopy.Count);
    }
}

/* This code example produces the following output:

one
two
three
four
five

Dequeuing 'one'
Peek at next item to dequeue: two
Dequeuing 'two'

Contents of the copy:
three
four
five

Contents of the second copy, with duplicates and nulls:



three
four
five

queueCopy.Contains("four") = True

queueCopy.Clear()

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

Queue コンストラクタ (ICollection)

指定したコレクションからコピーした要素を格納し、コピーした要素の数と同じ初期量を備え、既定の増加率を使用する、Queue クラスの新しいインスタンスを初期化します。

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

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

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

パラメータ

col

要素のコピー元の ICollection。

例外例外
例外の種類条件

ArgumentNullException

col が null 参照 (Visual Basic では Nothing) です。

解説解説

Queue の容量は、Queue が保持できる要素数になります。Queue に要素を追加すると、必要に応じて、再割り当てを行うことによって容量が自動的に増加します。容量を減らすには、TrimToSize を呼び出します。

増加率は、容量を増やす必要がある場合に、現在の容量に掛け合わせる数値です。増加率は Queue が生成された時点で決定します。

要素は、ICollection の IEnumerator によって読み取られる順序と同じ順序で、Queue にコピーされます。

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

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

Queue コンストラクタ


Queue コンストラクタ


Queue ジェネリック クラス

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

オブジェクトの先入れ先出しコレクションを表します。

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

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

型パラメータ

T

キュー内の要素の型を指定します。

解説解説
使用例使用例

Queue ジェネリック クラスのいくつかのメソッドを使用したコード例を次に示します。このコード例では、既定の容量で文字列のキューを作成し、Enqueue メソッドを使用して 5 つの文字列をキューに置きます。キューの要素は列挙されますが、キューの状態は変化しません。Dequeue メソッドを使用して、最初の文字列をキューから取り出します。Peek メソッドを使用してキュー内の次の項目を調べてから、Dequeue メソッドを使用してキューから取り出します。

ToArray メソッドを使用して配列を作成し、その配列にキュー要素をコピーしてから、IEnumerable を受け取る Queue コンストラクタに配列を渡してキューのコピーを作成します。コピーの要素が表示されます。

キューの 2 倍のサイズの配列が作成され、CopyTo メソッドを使用して配列の中央部で始まる配列要素をコピーします。Queue コンストラクタを再度使用して、先頭に 3 つの null 要素を含むキューの 2 つ目のコピーを作成します。

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

Imports System
Imports System.Collections.Generic

Module Example

    Sub Main

        Dim numbers As New
 Queue(Of String)
        numbers.Enqueue("one")
        numbers.Enqueue("two")
        numbers.Enqueue("three")
        numbers.Enqueue("four")
        numbers.Enqueue("five")

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

        Console.WriteLine(vbLf & "Dequeuing '{0}'", numbers.Dequeue())
        Console.WriteLine("Peek at next item to dequeue: {0}",
 _
            numbers.Peek())    
        Console.WriteLine("Dequeuing '{0}'", numbers.Dequeue())

        ' Create a copy of the queue, using the ToArray method and the
        ' constructor that accepts an IEnumerable(Of T).
        Dim queueCopy As New
 Queue(Of String)(numbers.ToArray())

        Console.WriteLine(vbLf & "Contents of the first copy:")
        For Each number As
 String In queueCopy
            Console.WriteLine(number)
        Next
        
        ' Create an array twice the size of the queue, compensating
        ' for the fact that Visual Basic allocates an extra array 
        ' element. Copy the elements of the queue, starting at the
        ' middle of the array. 
        Dim array2((numbers.Count * 2) - 1) As
 String
        numbers.CopyTo(array2, numbers.Count)
        
        ' Create a second queue, using the constructor that accepts
 an
        ' IEnumerable(Of T).
        Dim queueCopy2 As New
 Queue(Of String)(array2)

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

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

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

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

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

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

        Console.WriteLine("\nDequeuing '{0}'", numbers.Dequeue());
        Console.WriteLine("Peek at next item to dequeue: {0}", 
            numbers.Peek());
        Console.WriteLine("Dequeuing '{0}'", numbers.Dequeue());

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

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

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

        Console.WriteLine("\nqueueCopy.Contains(\"four\") = {0}",
 
            queueCopy.Contains("four"));

        Console.WriteLine("\nqueueCopy.Clear()");
        queueCopy.Clear();
        Console.WriteLine("\nqueueCopy.Count = {0}", queueCopy.Count);
    }
}

/* This code example produces the following output:

one
two
three
four
five

Dequeuing 'one'
Peek at next item to dequeue: two
Dequeuing 'two'

Contents of the copy:
three
four
five

Contents of the second copy, with duplicates and nulls:



three
four
five

queueCopy.Contains("four") = True

queueCopy.Clear()

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

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

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

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

Queue プロパティ


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

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

関連項目

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

Queue プロパティ


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

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

関連項目

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

Queue メソッド


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

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

関連項目

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

Queue メソッド


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

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

関連項目

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

Queue メンバ

オブジェクトの先入れ先出しコレクションを表します。

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


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

関連項目

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

Queue メンバ

オブジェクトの先入れ先出しコレクションを表します。

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


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

関連項目

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

待ち行列

(QUEUE から転送)

出典: フリー百科事典『ウィキペディア(Wikipedia)』 (2022/06/28 09:39 UTC 版)

ナビゲーションに移動 検索に移動
キュー > queue > 待ち行列

待ち行列(まちぎょうれつ、英: queue)



queue

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

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

キュー。(FIFO; First In, First Out)

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

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


英和和英テキスト翻訳

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

辞書ショートカット

すべての辞書の索引

「QUEUE」の関連用語

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

   

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



QUEUEのページの著作権

   
実用日本語表現辞典実用日本語表現辞典
Copyright © 2026実用日本語表現辞典 All Rights Reserved.
デジタル大辞泉デジタル大辞泉
(C)Shogakukan Inc.
株式会社 小学館
テレマーケティングジャパンテレマーケティングジャパン
Copyright (C)TELEMARKETING JAPAN, INC
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2026 Microsoft.All rights reserved.
日本オペレーションズ・リサーチ学会日本オペレーションズ・リサーチ学会
Copyright (C) 2026 (社)日本オペレーションズ・リサーチ学会 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というライセンスの下で提供されています。

©2026 GRAS Group, Inc.RSS