Papers     Signup     Site Map     Support     Directory  

Search Doing My Homework Papers


Papers > Technology > Java


Featured Papers from Direct Essays

1. JAVA 2

2. xml and java

3. Java vs C

4. Java

5. java


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



Username:

Password:

Pre-Written Papers
Browse through professionally written papers!

Browse through professionally written papers!

Custom Papers
Have Professional writers do your homework!

Professional writers will write custom papers for you!


Copyright 2003-2008 doingmyhomework.com. All rights reserved.