Implement a class called MostRecentlyInsertedQueue which implements the interface java.util.Queue . To reduce the amount of boilerplate code you have to write you may extend java.util.AbstractQueue . The purpose of this queue is to store the N most recently inserted elements. The queue should have the following properties: 1.The queue implements the interface java.util.Queue 2.The queue is bounded in size. The total capacity of the queue must be passed into the constructor. 3.New elements are added to the tail of the queue 4.The queue is traversed from head to tail 5.The queue must always accept new elements. If the queue is already full ( Queue#size() == capacity ), the oldest element that was inserted (the head) should be evicted, and then the new element can be added at the tail. The following code demonstrates the desired behavior: Queue queue = new MostRecentlyInsertedQueue(3); // queue.size(): 0, contents (head -> tail): [ ] queue.offer(1); // queue.size(): 1, contents (head -> queue.offer(2); // queue.size(): 2, contents (head -> queue.offer(3); // queue.size(): 3, contents (head -> queue.offer(4); // queue.size(): 3, contents (head -> queue.offer(5); // queue.size(): 3, contents (head -> int poll1 = queue.poll(); // queue.size(): 2, contents (head -> int poll2 = queue.poll(); // queue.size(): 1, contents (head -> queue.clear(); // queue.size(): 0, contents (head -> tail): tail): tail): tail): tail): tail): tail): tail): [ [ [ [ [ [ [ [ 1 ] 1, 2 ] 1, 2, 3 ] 2, 3, 4 ] 3, 4, 5 ] 4, 5 ], poll1 = 3 5 ], poll2 = 4 ] The primary evaluation criteria are correctness in the behavior of the queue as specified in the problem description, design, and clarity. Secondary criteria include performance and memory efficiency. Bonus #1: Implement ConcurrentMostRecentlyInsertedQueue , a thread-safe version of MostRecentlyInsertedQueue Bonus #2: Implement MostRecentlyInsertedBlockingQueue , a thread-safe variant of MostRecentlyInsertedQueue that implements ja va.util.concurrent.BlockingQueue
-mostrecentlyinsertedqueue's Introduction
-mostrecentlyinsertedqueue's People
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. ๐๐๐
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google โค๏ธ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.