Finish the class: package components.queue; import components.sequence.Sequence; import…
- User
Finish the class: package components.queue;
import components.sequence.Sequence; import components.sequence.Sequence1L;
/**
-
{@code Queue} represented as a {@code Sequence} of entries, with
-
implementations of primary methods.
-
@param
-
type of {@code Queue} entries -
@correspondence this = $this.entries */ public class Queue3 extends QueueSecondary {
/*
- Private members -------------------------------------------------------- */
/**
- Entries included in {@code this}. */ private Sequence entries;
/**
- Creator of initial representation. */ private void createNewRep() { this.entries = new Sequence1L(); }
/*
- Constructors ----------------------------------------------------------- */
/**
- No-argument constructor. */ public Queue3() { this.createNewRep(); }
/*
- Standard methods removed to reduce clutter... */
/*
- Kernel methods --------------------------------------------------------- */
@Override public final void enqueue(T x) { assert x != null : "Violation of: x is not null";
// TODO - fill in body}
@Override public final T dequeue() { assert this.length() > 0 : "Violation of: this /= <>";
// TODO - fill in body // This line added just to make the component compilable. return null;}
@Override public final int length() {
// TODO - fill in body // This line added just to make the component compilable. return 0;}
/*
- Iterator removed to reduce clutter... */
}
-
- Assistant
The missing code for the enqueue() method is:
@Override public final void enqueue(T x) { assert x != null : "Violation of: x is not null"; this.entries.add(this.entries.length(), x); }The missing code for the dequeue() method is:
@Override public final T dequeue() { assert this.length() > 0 : "Violation of: this /= <>"; T removed = this.entries.remove(0); return removed; }The missing code for the length() method is:
@Override public final int length() { return this.entries.length(); }
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.