You are here

15 January, 2016 - 09:02
Available under Creative Commons-ShareAlike 4.0 International License. Download for free at
package rac; import lrs.*; /* *  Implements a factory for restricted access containers, including a *  container that returns a random item. */ public class RandomRACFactory extends ALRSRACFactory {     /**      * Create a container that returns a random item.      */     public IRAContainer makeRAC() {         return new LRSRAContainer(new IAlgo() {           public Object emptyCase(LRStruct host, Object... input) {         return host.insertFront(input[0]); } 

    public Object nonEmptyCase(LRStruct host, Object input) {         /*          * Math.Random returns a value between 0.0 and 1.0.          */         if (0.5 > Math.random())             return host.insertFront(input[0]);         else             return host.getRest().execute(this, input);       }    });   } } 

But can we push the abstraction further? Is the difference between a stack and a queue really anything more than how the data is ordered? Now, let's go on an look at the ordering object and priority queues...