function [t,ok]=TreeStack(op,push)
% TreeStack Implement a stack that can hold
%   structure trees (or any other objects).

% Author: D. Orofino
% Copyright 1984-2000 The MathWorks, Inc. 
% $Revision: 1.3 $ $Date: 2000/06/01 03:16:19 $

persistent trees;
if ~iscell(trees), trees={}; end

switch op
case 'pop'
   % pop   
   if isempty(trees),
      ok=0;
      t=[];
      trees={};
   else
      ok=1;
      t=trees{end};
      trees=trees(1:end-1);
   end
   
case 'push'
   trees(end+1)={push};
   t=trees;
   ok=1;
   
case 'query'
   t=trees;
   ok=1;
   
case 'reset'
   trees={};
   t=trees;
   ok=1;
   
end

% [EOF] TreeStack.m
