list - 如何在 Ada 中制作二维链表
问题描述
对于我正在处理的项目,我想使用 Ada.Collections.Doubly_Linked_Lists 创建一个包含字符串的 2d(列表列表)。我无法弄清楚如何在没有任何 3rd 方库的情况下完成这项工作。任何帮助表示赞赏!
解决方案
我同意@Rich 和@trashgod 的评论,但仍然是一个小例子:
主文件
with Ada.Text_IO; use Ada.Text_IO;
with Ada.Containers; use Ada.Containers;
with Ada.Containers.Doubly_Linked_Lists;
with Ada.Containers.Indefinite_Doubly_Linked_Lists;
procedure Main is
-- Inner list (Strings are indefinite types).
package L_Strings is
new Indefinite_Doubly_Linked_Lists (String);
use L_Strings;
-- Outer list.
package L_L_Strings is
new Doubly_Linked_Lists (L_Strings.List);
use L_L_Strings;
-- Cursors for pointing to elements in either lists.
LC : L_Strings.Cursor;
LLC : L_L_Strings.Cursor;
-- Create an empty outer list.
LLS : L_L_Strings.List := L_L_Strings.Empty_List;
begin
-- Add two empty inner lists to the outer list.
LLS.Append (L_Strings.Empty_List);
LLS.Append (L_Strings.Empty_List);
-- Add some strings to the first inner list (of strings).
LLC := First (LLS);
LLS (LLC).Append("This");
LLS (LLC).Append("is");
LLS (LLC).Append("a");
-- Add some strings to the second inner list (of strings).
LLC := Next (LLC);
LLS (LLC).Append("nested");
LLS (LLC).Append("linked");
LLS (LLC).Append("list");
-- Loop over the elements of the outer and inner list.
for Outer_Elem of LLS loop
for Inner_Elem of Outer_Elem loop
Put (Inner_Elem & " ");
end loop;
New_Line;
end loop;
end Main;
输出
This is a
nested linked list
推荐阅读
- python - 如何使用 Selenium driver.find_elements_by_xpath 提取位置的名称。没有返回数据。试图打印出 Tit Heng Phone Shop
- c# - 当 signalR 连接丢失到集线器代理时,始终保持重新连接状态 2 分钟
- sql - 将行值转换为列名
- amazon-web-services - AWS API Gateway 不接收发布请求
- spring-boot - 在特定时间窗口中每 30 分钟运行一次的作业的 Cron 表达式
- shopify - 更改主题中的 shopify 标签
- java - 您应该在 `onBillingServiceDisconnected()` 中添加什么?
- envoyproxy - 在反向代理中寻找“proxy_set_header”的 Envoy 示例
- python-2.7 - Ansible 列表未排序
- excel - VBA 和 Excel:绕过受 Siteminder 保护的身份验证浏览网站