Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8627261
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T08:13:59+00:00 2026-06-12T08:13:59+00:00

I’ve programmed a stack of generic numbers in Ada using a ‘Indefinite_Doubly_Linked_Lists’ list. Pop

  • 0

I’ve programmed a stack of generic numbers in Ada using a ‘Indefinite_Doubly_Linked_Lists’ list.

Pop & push operations are implemented with append and delete_last but for a sorting method I would need to access individual items of the list.

I did work out a sorting method using only append/prepend delete_last/first but the result is far from elegant (and maybe not correct)

procedure sort is
   elem1: Item;
   elem2: Item;
   --l is a package-private Indefinite_Doubly_linked_lists'
begin
   if Integer(MyList.Length(l)) > 1 then
      for i in 0 .. Integer(MyList.Length(l))-1 loop
         for j in 0 .. Integer(MyList.Length(l))-1 loop
            --Inner sort loop
            elem1 := MyList.Element(l.first);
            l.Delete_First;
            elem2 := MyList.Element(l.first);
            l.Delete_First;
            if elem1>elem2 then
               l.Prepend(elem1);
               l.Append(elem2);
            else
               l.Prepend(elem2);
               l.Append(elem1);
            end if;
         end loop;
      end loop;
   end if;
end;

How do can I access individual elements (or iterate over) from a list of generic type?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T08:14:00+00:00Added an answer on June 12, 2026 at 8:14 am

    A couple things:

    Unless the point of your exercise is writing a sort, you could just…uh…use the generic sort:

    package List_Sort is new MyList.Generic_Sorting;
    

    If you’re using an Ada 2012 compiler, generalized looping gives you easy access to each element:

    procedure Iterate is 
    begin
       for Elem of L loop
          Put_Line(Item'Image(Elem));
       end loop;
    end Iterate;
    

    If you’re not using Ada 2012, you can make due with cursors, either on their own:

    procedure Cursor_Iterate is
    
       C : MyList.Cursor := L.First;
    
       use type MyList.Cursor;
    
    begin
       loop 
          exit when C = MyList.No_Element;
          Put_Line(Item'Image(MyList.Element(C)));
          MyList.Next(C);
       end loop;
    end Cursor_Iterate;
    

    or with MyList’s Iterate procedure:

    procedure Iterate
      (Container : in List;
       Process   : not null access procedure (Position : in Cursor));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I am reading a book about Javascript and jQuery and using one of the
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
We're building an app, our first using Rails 3, and we're having to build
I have an array which has BIG numbers and small numbers in it. I
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I have thousands of HTML files to process using Groovy/Java and I need to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.