Example Code

Singly Linked List (No references or classes)

Code and Documents

Attachment

I wanted to see if it was possible to have an implementation without classes or references.

  

The ideal type would be a cluster with two elements, a value, and a singly linked list but if you try and do that the IDE throws an error about not being able to have recursive data types. Instead, we can just use a variant for the "next" element

singly linked type.PNG

And here's how you can link them. You can see from the indicator that all the data is in there:

append2.PNG

 

We can also implement other functions like print, insert, append to other side, reverse list, sort etc:

reverse list.png

Here's what sort looks like:

 

Sort.PNG

 

Things that would be nice to have for future work:

 

 

Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.

Comments
Eric.M
Active Participant
Active Participant
on
That's an interesting pattern and I can think of a couple applications. However, you should not call it a linked list. You crafted a kind of variant tree instead. In a list, elements are siblings, they do not share a common parent, while you cluster is built on a strict (and unique) composition relationship— i contains i+1 that itself contains i+2 etc... List items are also easily interchangeable with no effort/performance penalty because they're based on references/pointers. You did manage to do a Sort on your tree but it costs a lot of memory as its needs to copy each element out the original tree into the sorted one. Still a good idea to build recursive data containers. --Eric

Eric M. - Senior Software Engineer
Certified LabVIEW Architect - Certified LabVIEW Embedded Systems Developer - Certified LabWindows™/CVI Developer
Neosoft Technologies inc.

nanocyte
Active Participant
Active Participant
on

Thank you for the feedback!

 

 

I was trying to follow this type of linked list. By using swap values, you should be able different lists and link them back together without copying. You'll notice that in bubble, everything is done on the shift register and ideally, should be "in place". If I'm mistaken here, let me know.

 

If you think recursive data structures should exist without the variant, please kudos the idea. I think it will enable users to advance what can be made in LabVIEW.

Contributors