MATLAB 链表 [英] MATLAB linked list

查看:33
本文介绍了MATLAB 链表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

MATLAB 中实现链表的方法有哪些?

What are some possible ways to implement a linked list in MATLAB?

注意:我问这个问题是为了教学价值,而不是实用价值.我意识到如果你真的在 MATLAB 中滚动你自己的链表,你可能做错了什么.但是,我是本学期 MATLAB 密集型课程的 助教,我的目标是提出这个问题是为了更好地理解语言的一般结构.由于 MATLAB 的通用编程工具有点不寻常,我觉得这样的问题可以帮助我理解它们.

Note: I am asking this question for pedagogical value, not practical value. I realize that if you're actually rolling your own linked list in MATLAB, you're probably doing something wrong. However, I'm a TA for a class that is MATLAB-intensive this semester, and my goal in asking this question is to understand the general structure of the language better. As MATLAB's general purpose programming facilities are a bit unusual, I feel a question like this will help me understand them.

推荐答案

MATLAB 可以访问 Java:

MATLAB has access to Java:

>> a=java.util.LinkedList;
>> li=a.listIterator;
>> li.add(2);
>> li.add(int8(77));
>> li.add(77);
>> li.add(boolean(true));
>> li.add('Mr. Bill');
>> li.previous();
>> li.add([1 2 3 4 5]);
>> a

a =

[2.0, 77, 77.0, true, [D@66a917, Mr. Bill]

>> a.get(4)

ans =

     1
     2
     3
     4
     5

这种方法的一个缺点是因为 MATLAB 无法将任意 MATLAB 对象编组或序列化为 Java,因此您只能使用 浮点数、整数(需要在 MATLAB 中使用 int8 等进行转换)、布尔值、字符串、数组和Java 对象.

The one downside of this approach is because MATLAB doesn't have a way to marshal or serialize arbitrary MATLAB objects into Java, you're limited to floating point numbers, integers (need to cast them in MATLAB using int8 etc.), booleans, strings, arrays, and Java objects.

这篇关于MATLAB 链表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆