gkamani2011
gkamani2011

Reputation: 223

Ada - list of lists

I am working on an ADA project. Essentially what I need to do is I create a list in which I the first node is the main node or tower and every consecutive node is a tower than the main head is connected to.

So suppose I have a list like A -> B -> D -> E -> F, it means that the tower A is connected to tower B, D, E and F.

Now I also need to have a list to store all the main towers. So suppose I have A ->B -> D -> E -> F, and I have C->X->Y->Q, and E->P->R, the list of lists should be like:

A-> C-> E ( essentially the list of all the main nodes).

i need to do this using generic type lists.

I know this is a bit confusing. But what should I do about it? Ada is so confusing to me.

Thanks in advance guys :)

Upvotes: 0

Views: 1399

Answers (2)

Jacob Sparre Andersen
Jacob Sparre Andersen

Reputation: 6601

Here is the full project description - just so we know what the task is.

The ban on using package Ada.Containers.Doubly_Linked_Lists can be seen as an irelevant distraction.

One thing I've noticed, which may simplify the task is that there is not mention whatsoever of communications links being removed/disappearing.

Another nice detail of the problem description is that there are no performance requirements.

The only tasks your abstract data structure should be able to handle are:

  • Add a directional link from one node to another.
  • Answer if there is a directional link from one node to another.

(I'm not going to tell you more, as I don't want you to get in too much trouble with your professor.)

Upvotes: 1

Simon Wright
Simon Wright

Reputation: 25491

If you're allowed to use someone else's Ada 95 container library, you could try the Ada 95 Booch Components. If you (are allowed to) do this, don't use the Lists packages, use Collections instead:

with BC.Indefinite_Unmanaged_Containers.Collections;
procedure Towers is

   package Abstract_Main_Nodes
   is new BC.Indefinite_Unmanaged_Containers (String);
   package Main_Nodes is new Abstract_Main_Nodes.Collections;

   package Abstract_All_Main_Nodes
   is new BC.Indefinite_Unmanaged_Containers (Main_Nodes.Collection,
                                              "=" => Main_Nodes."=");
   package All_Main_Nodes is new Abstract_All_Main_Nodes.Collections;

end Towers;

and

with Towers; use Towers;
procedure Main is

   Main_Tower : Main_Nodes.Collection;
   Main_Towers : All_Main_Nodes.Collection;

begin

   Main_Nodes.Append (Main_Tower, "A");
   Main_Nodes.Append (Main_Tower, "B");
   Main_Nodes.Append (Main_Tower, "D");
   Main_Nodes.Append (Main_Tower, "E");
   Main_Nodes.Append (Main_Tower, "F");
   All_Main_Nodes.Append (Main_Towers, Main_Tower);

   Main_Nodes.Clear (Main_Tower);
   Main_Nodes.Append (Main_Tower, "C");

etc.

Upvotes: 1

Related Questions