0

Java の Queue クラスの enterQueue() と leaveQueue() の例を参照している人はいますか? enterQueue() と leaveQueue() のアクションを示す割り当てを実行しようとしていますが、API で何も見つからないようです.Peek、Poll、およびサイズは既に実行しました。実際には関係ないと思いますが、そのコードはここに添付されています。

Stack st = new Stack();
       Queue<String> q = new LinkedList<String>();
       String element;

       st.push("A");
       st.push("B");

       System.out.println("\fInitial Stack contents: "+st);

       q.addAll(st);
       st.clear();

       Iterator itr = q.iterator();

       System.out.println("\nInitial Queue size: "+q.size());
       System.out.println("It contains "+q+" while the stack is now "+st+"\n");

       while(itr.hasNext()) {
           String iteratorValue = (String)itr.next();
           System.out.println("Next in queue: "+iteratorValue);
        }

       //Peek : Look at value, don't remove it
       System.out.println("\nQueue Peek: "+q.peek());

       // Poll : Remove first value from queue
       element = q.poll();
       System.out.println("\nQueue Poll: "+element);

       System.out.println("\nQueue Size now: "+q.size());
       System.out.println("Queue remainder: "+q);
4

3 に答える 3

0

This is identical to an exercise in the COMP268 introductory Java course at Athabasca University--and if that's the source then the best answer is "ask your tutor, or post the question in the course Moodle forum after checking to see if it has already been asked and answered there."

That's what your tutor gets paid to do, and what the Moodle forums are for, and it's not appropriate to substitute stackoverflow forums, since then your tutor doesn't know you're having problems and your fellow students don't know the question has been asked here instead and can't benefit from the answers posted here. Moreover, there's also the temptation to "borrow" code that's posted here or in other online forums, and forget that that's not the intention of the exercise--and could possibly get you a severe penalty for cheating.

Your tutor knows about these online forums too...

于 2013-10-24T23:00:26.193 に答える
0

enterQueueこの方法は何ですか?
Java は ADT キューを実装し、メソッドに特定の名前を使用します。無関係なキューに挿入するための名前の
場合。 Queue には特定の機能の FIFO があり、実装で特定の名前を使用する義務はありませんが、従来はfor queue forを使用しますenterQueue
add /removepush/popStack

于 2013-03-27T21:49:46.527 に答える
0

実装するメソッドについて述べたことから、インストラクターは、キューの追加/削除関数を作成したり、ライブラリで提供されている関数を使用したりしたくないと確信していますか? これらの方法についても聞いたことがないので、少なくとも私にはそう聞こえます。プログラムの名前が MyQueue.java であることを考えると、ライブラリから作成して使用しないように思えます。

于 2013-03-27T21:57:49.247 に答える