comp.lang.ada
 help / color / mirror / Atom feed
* urgent help needed!!!
@ 1997-03-29  0:00 yus000
  1997-03-31  0:00 ` Robert Dewar
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: yus000 @ 1997-03-29  0:00 UTC (permalink / raw)



Hi, i have a urgent question.

I am doing assignment on stacks.  We have to declare the stack as "limited
private type"

As a result, in my main program, i need to initiate the stack.  Do i use

with Text_IO; use Text_IO;
with ordered_stack; use ordered_stack;
procedure main is

begin

declare

    w: stack;   -- line 7
    m: integer := 4;
    n: integer := 3;
    k: integer :=  2;

begin

   push(w, m);
   push(w, n);
   push(w, k);

end;

end main;


*** i get the error" subtype mark required in this context"

How do i arrange my main program???

I tried to change it to : type w is new ordered_stack, but i still get
errors.  Please help!!!

thanks.
----------------------------------------------------------------
with ordered_stack; --use ordered_stack;
with Text_IO; use Text_IO;
procedure testorder is
 a,b,c,d : integer;

begin

declare
    use ordered_stack;
    a : integer := 4;
    b : integer := 3;
    c : integer := 2;
    d : integer := 1;

   -- a, b, c, d : integer;
    type w is new ordered_stack;

    --type p is new ordered_stack;

    --subtype w is p; -- stack;

begin

  -- a := 4;
  -- b := 3;
   --c := 2;
   --d := 1;
--begin

   push(w,a);
   push(w,b);
   push(w,c);
   push(w,d);

   put(" is going to print");
   New_Line;

   print(w);

end;

end testorder;
----------------------------------------------------------
------------------------------------------------------------------
with Gnat.IO; use Gnat.IO;

package body ordered_stack is

   procedure push(s: in out stack; x: in integer) is
      k: cell_ptr;
   begin
      k := new cell'(value=>x, next=>null);
      s.list.next := k;
      s.list := k;

      s.count := s.count + 1;


   end push;
  --////////////////////////////////////////

   function empty (s: stack) return Boolean is
   begin
      return s.list = null;
   end empty;

  --/////////////////////////////////////////////

   procedure pop(s: in out stack; x: out integer)is
   begin
       x:= s.list.value;
       s.list := s.list.next;

   end pop;

  --////////////////////////////////////////////////
function top(s: stack) return integer is
begin
     return s.list.value;
end top;

--////////////////////////////////////////////////////


procedure print(s: out stack) is

  i: integer;
  m: integer;
begin

   m := s.count;

   Put("The ordered stack is as follows");
   New_Line;

   for i in 1 .. m loop

       put(integer(s.list.value));
   end loop;
   New_Line;

end print;

end ordered_stack;
---------------------------------------------------------------------

*******************************************************************
package ordered_stack is

       type stack is limited private;

       procedure push(s: in out stack; x: in integer);

       function empty (s: stack) return Boolean;

       procedure pop (s: in out stack; x: out integer);

    function top (s: stack) return integer;

  --   function top return integer;

       procedure print(s: out stack);


private
          type cell;
          type cell_ptr is access cell;

          type cell is
           record
              value: integer;
              next:  cell_ptr;
           end record;

           type stack is
              record

             --max: constant := 100;
         --type integer_vector is array(integer range<>) of integer;
          --s: interger_vector(1 .. max);
          --top: integer range 0 .. max := 0;

            count: integer:= 0;
           list: cell_ptr;
        end record;
end;
*********************************************************************

-------------------==== Posted via Deja News ====-----------------------
      http://www.dejanews.com/     Search, Read, Post to Usenet




^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~1997-04-01  0:00 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1997-03-29  0:00 urgent help needed!!! yus000
1997-03-31  0:00 ` Robert Dewar
1997-03-31  0:00 ` Nick Roberts
     [not found]   ` <01bc3dd0$ff5bf600$7e0464c3@edi-c>
1997-03-31  0:00     ` Nick Roberts
1997-04-01  0:00 ` Larry Kilgallen

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