image thumbnail

Comparison of C++, Java, Python, Ruby and MATLAB Using Object Oriented Example

by

 

28 Feb 2008 (Updated )

RedBlack Tree Binary Search Example Used to Compare of C++, Java™, Python, Ruby and MATLAB® Code

Editor's Notes:

This file was selected as MATLAB Central Pick of the Week

test_RedBlackTree
% // ==================================
% // test program
% // ==================================
%
% Copyright 2008-2009 The MathWorks, Inc


function test_RedBlackTree

nodelist= [11,4,8,14,17,6,9,7,16,15,13,5,19,18,12,10,3,20,1];
root = RedBlackTree(2);
for n=nodelist
    root.insert(n)
end

% class implementing the NodeVisitor interface
v=NodeVisitor;
fprintf('M      = ');
root.inorder(v,0);
fprintf('\n');

% find the specified element and print its value
x=root.find(16);
fprintf([x.s '\n']);

Contact us