先進先出隊列的典型用例

public static int[] readInts(String name)
{
    In in =  new In(name);
    Queue<Integer> q = new Queue<Integer>();
    while(!in.isEmpty())
        q.enqueue(in.readInt());//先進
    
    int N = q.size();
    int[] a = new int[N];
    for (int i = 0; i < N; i++)
        a[i] = q.dequeue();//先出
    return a;
}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章