MATLAB链表 [英] MATLAB linked list

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

问题描述

MATLAB 中实现链接列表的几种可能方法是什么?

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

注意:我问的这个问题是教学价值,而不是实用价值.我意识到,如果您实际上是在MATLAB中滚动自己的链接列表,则可能是您做错了什么.但是,对于这个学期需要大量学习MATLAB的课程,我是 TA 提出这个问题是为了更好地理解语言的总体结构.由于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,因此您只能使用

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天全站免登陆