comp.lang.ada
 help / color / mirror / Atom feed
From: mfb@mbunix.mitre.org (Michael F Brenner)
Subject: Re: comparing  data
Date: 1997/10/03
Date: 1997-10-03T00:00:00+00:00	[thread overview]
Message-ID: <613ccc$6vn@top.mitre.org> (raw)
In-Reply-To: Pine.OSF.3.91.971001211838.21484A-100000@condor.stcloudstate.edu


Well, maybe it can be done in one IF statement, but here is a 
solution that takes a few IF statements. 

Assuming that these three values are in a random access
container, one way to approach the problem of displaying 
the lowest value is as follow.

      type indexes is range 1..3;
      type values  is range 1 .. 1_000_000;
      package education is new links_on_a_chain (values, indexes);

      education.rtm(5); -- The first one is on the linked list
      education.rtm(1); -- The second value is on the linked list
      education.rtm(9284); -- The Third value is on the linked list
     
      -- The three values are in the container called education.
 
      if education.remember (1) >= education.remember(2) and
         education.remember (1) >= education.remember(3) then
         education.delete_fact (1); -- One is the biggest
      end if;

      if education.remember (2) >= education.remember(1) and
         education.remember (2) >= education.remember(3) then
         education.delete_fact (2); -- Two is the biggest
      end if;
      
      if education.remember (3) >= education.remember(1) and
         education.remember (3) >= education.remember(2) then
         education.delete_fact (3); -- Three is the biggest
      end if;
        
      -- At this point, the largest, and possibly the second
      -- largest element in the container has been deleted.

      if education.number_of_elements = 1 then
        text_io.put_line (values'image (education.arb));
        raise success;
      end if;

      education.effect_a_reorganization;

      -- At this point, there are two elements in the
      -- container, whose indexes are 1 and 2.    

      if education.remember (1) >= education.remember (2) then
        education.delete_fact (1);
      else
        education.delete_fact (2);
      end if;

      education.effect_a_reorganization;
 
      -- At this point, there is one element of the list.

      text_io.put (values'image (education.remember (1)));
      text_io.put_line ("is the smallest value");




      parent reply	other threads:[~1997-10-03  0:00 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1997-10-01  0:00 comparing data Big B
1997-10-02  0:00 ` Peter Hermann
1997-10-02  0:00 ` Tom Moran
1997-10-03  0:00 ` Michael F Brenner [this message]
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox