如何在Pascal中实现矩阵运算?
我需要用矩阵实现运算,并且矩阵的大小必须是可变的。 我想出的唯一解决方案是使用链表:
[pointer to this row, pointer to another row] -> [element 1,1; link to another element] -> [element 1,2, link to another element] -> .... -> [nil]
|
v
[pointer to this row, pointer to another row] ...
...
但在我看来有点复杂..有更好(更简单)的解决方案吗?
感谢你们!
I need to implement operations with matrices and size of matrix has to be variable. The only solution I came up with is to use linked list:
[pointer to this row, pointer to another row] -> [element 1,1; link to another element] -> [element 1,2, link to another element] -> .... -> [nil]
|
v
[pointer to this row, pointer to another row] ...
...
But it seems to me a little bit complex.. Is there a better (and easier) solution?
Thank you guys!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
一种方法是使用 GetMem 来分配足够的内存。 GetMem 似乎得到了广泛的支持。
One approach would be to use GetMem to allocate exactly enough memory. GetMem seems widely supported.
任何现代 pascal 变体(Delphi)都可以让您创建动态(运行时大小)数组。
如果该语言不支持多维动态数组,您可以自己处理寻址:
这种寻址将比以下链接列表快得多。
Any modern pascal variant (Delphi) will let you create dynamic (runtime sized) arrays.
If the language doesn't support multidimensional dynamic arrays you can take care of the addressing yourself:
This kind of addressing will be a lot faster than following linked lists.