|
Featured Papers from Direct Essays
|
|
|
|
|
|
This is a preview of a paper to view the full text you need to signup and login.
|
Java
|
|
|
1. Complete the implementation of the following method, observing the following restrictions: Ć you don't declare any additional local variables or allocate new objects. Ć you don't store null in the Queue or Stack. Ć neither StackInterface or QueueInterface has a size method (but they do have isEmpty methods) Answer: public static void purge(QueueInterface q) { // pre: q is not null, q contains only Integer objects // post: all negative Integers are removed from q, // order of other elements in q remains unchanged StackInterface s = DataFactory.makeStack(); //Check if the values of the Integer objects in q are negative or positive. If positive, put //them into stack s and remove from q. Otherwise, remove from q only. while (q.isEmpty() = = false) { if (q.peek.intValue( ) < 0) { q.dequeue( ); } else { s.push (q.dequeue( )); } } //Put back all positive integer objects into q, but in a reverse order. while (s.isEmpty( ) = = false) { q.enqueue(s.pop); } //Put the integer objects into q in the original order. while (q.isEmpty( ) = = false) { s.push (q.dequeue( )); } while (s.isEmpty( ) = = false) { q.enqueue(s.pop); } } 2. Consider the following interface. public interface ExtendedStack extends StackInterface { public Object pull(); // pre: this is not empty // post: the item on the bottom of the stack (the item first in) // is removed and returned } Here are three suggested classes that could implement this ADT: public class SinglyLinkedExtendedStack implements ExtendedStack {// Implementation using a singly-linked list private Node head; private int count; ...
|
|
|
To link to this page, copy the following code to your site:
|
|
Paper Information
|
|
|
Title: Java
Words: 1039 Rating: None Pages: 4.2 submitted by: WongChoi
If you think this paper shouldn't be here then
|
|
|
|
|
Signup & Login
|
|
|
If you don't currently have a login then Signup here
|
|
|
|
|
Pre-Written Papers
|
|
|
|
|
|
|
|
Custom Papers
|
|
|
|
|
|
|
|