rosevorti.blogg.se

Ada 95 linked list stack display
Ada 95 linked list stack display






ada 95 linked list stack display

In the case of arrays, the size is limited to the definition, but in linked lists, there is no defined size. These nodes consist of the data to be stored and a pointer to the address of the next node within the linked list. In Ada, the first is implemented in _Linked_Lists, the latter in arrays accommodate similar types of data types, linked lists consist of elements with different data types that are also arranged sequentially.Ī linked list is a collection of “nodes” connected together via links. Note: in your question, you refer to both a doubly linked list and an equivalent of std::vector. Which yields (depending on the state of the random generator): Move element from one list to the other. Pos : Count_Type := Random (Gen, 1, List.Length) Procedure Shuffle_List (List : in out DLL.List) is With GNAT.Random_Numbers use GNAT.Random_Numbers Shuffle_list.adb with Ada.Containers use Ada.Containers - for Count_Type Procedure Shuffle_List (List : in out DLL.List) With package DLL is new _Linked_Lists () You might try something like this (see also RM 12.7): I just want to write the equivalent in Ada to these four lines of C++: template

#Ada 95 linked list stack display full#

In the example I have just defined Length, but typically I want the function to operate on the full interface of doubly_linked_list, which means writing a whole bunch of code identically, just for different doubly_linked_list element_types. With this approach, you have to redefine every function of the list type you want to use. I want something less cumbersome that works for doubly_linked_lists. Procedure shuf is new shufit.Foo(element_type => Integer, list_type => IntArray, Length => ArrayLength) īut that's not what I'm trying to achieve. Type IntArray is array (1.10) of Integer įunction ArrayLength (List : in IntArray) return Integer is The nice thing about this is that I can make the same function work for arrays as for doubly_linked_lists: procedure Main Procedure shuf_intdll is new shufit.Foo(element_type => Integer, list_type => int_dll_type, Length => IntDLL_Length) Usage: package int_dll is new _Linked_Lists(Element_Type => Integer) įunction IntDLL_Length (List : in int_dll_type) return Integer is Procedure Foo (List : in out list_type) is With function Length (List : in list_type) return Integer At this point, we know nothing about the type involved, which means we need to specify every function of doubly_linked_list that we need to use. The only thing I can think of is to just throw all the generics at the function we can imagine. package shufit_pack is new shufit(element_type => Integer) Having moved the element_type generic up to the package level, and fixed the error 'type derived from tagged type must have extension' with the 'with null record' suffix on the type definition, this compiles but the calling code must use this specifically defined type, which means if we also want a Bar procedure that operates on the same type, it is not possible to make these independently. Type int_dll_type is new int_dll.List with null record Attempt 2 - generic procedure instantiating the doubly_linked_list package with _Linked_Lists But in Ada, I don't seem to be able to refer to the equivalent in two different packages, without one including the other. In C++, I can have a 'vector' instantiated in two completely different namespaces/classes, and yet they refer to the same type. Even if we could do this, when trying to call this we need to make an int_dll_type outside the function definition and yet matching it - which doesn't seem to work in Ada. That approach won't work because we can't create a package in the generic section. Procedure Foo (List : in out int_dll_type) Package int_dll is new _Linked_Lists(Element_Type => Integer) Attempt 1 - generic procedure instantiating the doubly_linked_list package with _Linked_Lists However, trying to do the analoguous with _Linked_List(T).List leads to problems. So in the case of arrays, you can neatly genericize precisely that which may differ in instantiations. procedure IntArrayFoo is new Foo(element_type => Integer, array_type => Integer_Array) Procedure Shuffle_Array (List : in out Array_Type) Ī procedure can be instantiated from this given an element_type and strictly a corresponding array_type, while the bounds of the array are still left to the particular instantiation to vary. Type Array_Type is array (Positive range ) of element_type

ada 95 linked list stack display ada 95 linked list stack display ada 95 linked list stack display

If possible, how would I write an Ada generic function operating on doubly_linked_lists of any type of element? The following function specification illustrates what I want by constraining Array_Type to be an array of the element_type given.








Ada 95 linked list stack display