Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
723 views
in Technique[技术] by (71.8m points)

data structures - MATLAB linked list

What are some possible ways to implement a linked list in 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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

56.8k users

...