rb_demo.m

来自「data structures C programs」· M 代码 · 共 34 行

M
34
字号
function h=rb_demo
% RB_DEMO
%
%  Demonstrate how a Red-Black binary tree is being used to produce a sorted
%  list of words. A graph of the resulting tree is shown.

% Copyright (c) MathWorks Inc. 1998-2001. All rights reserved.

h=rb_new;

weights=(96.^(14:-1:0))';
tic
fid=fopen('random','r');
for i=1:50
  line=fgetl(fid);
  if isempty(line);
    line=' ';
  end
  key=line-' ';
  key(length(weights))=0;
  key=key*weights;
  h=rb_put(h,line,key);
end
fclose(fid);
toc

rb_inord(h,'disp');

if nargout==0
  rb_graph(h);
  rb_free(h);
end

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?