image thumbnail
from Order book simulation by Dimitri Shvorob
(a naive artificial stock market)

Queue
classdef Queue < handle
   
   properties (SetAccess = protected)
       Values
   end
            
   methods 
       
       function[out] = isempty(obj)
           out = isempty(obj.Values);
       end
       
       function clear(obj)
           obj.Values = [];
       end
       
       function[out] = length(obj)
           out = length(obj.Values);
       end
       
       function put(obj,val)
           if isempty(obj)
              obj.Values = val;
           else
              obj.Values(end+1) = val;
           end
       end
              
       function[out] = get(obj)
           if ~isempty (obj)
               out = obj.Values(1);
               obj.Values(1) = [];
           else
               out = [];
           end    
       end
       
       function[out] = peek(obj)
           if ~isempty(obj)
               out = obj.Values(1);
           else
               out = [];
           end    
       end
              
       function disp(obj)
           disp('Queue (shown head to tail)')
           if isempty(obj)
              disp('<empty>')
           else
              for i = 1:length(obj.Values)
                  disp(obj.Values(i))
              end
           end    
       end
                  
   end   
    
end

Contact us at files@mathworks.com