comp.lang.ada
 help / color / mirror / Atom feed
* How can i print the element poped from a generic STACK
@ 2000-11-07  0:00 jordan
  2000-11-07  0:00 ` Steve Folly
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: jordan @ 2000-11-07  0:00 UTC (permalink / raw)


Dear all,
i want to ask that how can i print the element poped from a generic
STACK.
i have write the following code:
=====================================================
with TEXT_IO;
use TEXT_IO;

procedure sample is

generic
 SIZE : POSITIVE;
 type ITEM is private;
package STACK is
 procedure PUSH(E : in ITEM);
 procedure POP (E : out ITEM);
end STACK;

package body STACK is
 type TABLE is array (POSITIVE range <>) of ITEM;
 SPACE : TABLE(1..SIZE);
 INDEX : NATURAL := 0;

 procedure PUSH(E : in ITEM) is
 begin
  INDEX := INDEX + 1;
  SPACE(INDEX) := E;
 end PUSH;

 procedure POP(E : out ITEM) is
 begin
  E := SPACE(INDEX);
  INDEX := INDEX - 1;
 end POP;
end STACK;

 package stackOfInt is new STACK(100, INTEGER);
 use stackOfInt;

 package INT_IO is new TEXT_IO.INTEGER_IO(INTEGER);
 use INT_IO;

 i : Integer;

begin


 stackOfInt.push(20);

 Put(stackOfInt.pop(i));            <------------- error!!!

end sample;

==============================================
i want to print the element of integer 20 on the screen, how can i do??
is my implementation wrong???





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

* Re: How can i print the element poped from a generic STACK
  2000-11-07  0:00 How can i print the element poped from a generic STACK jordan
  2000-11-07  0:00 ` Steve Folly
@ 2000-11-07  0:00 ` Robert A Duff
  2000-11-07  0:00 ` Larry Hazel
  2 siblings, 0 replies; 4+ messages in thread
From: Robert A Duff @ 2000-11-07  0:00 UTC (permalink / raw)


jordan <huikeith@hotmail.com> writes:

>  package stackOfInt is new STACK(100, INTEGER);
>  use stackOfInt;
> 
>  package INT_IO is new TEXT_IO.INTEGER_IO(INTEGER);
>  use INT_IO;
> 
>  i : Integer;
> 
> begin
> 
> 
>  stackOfInt.push(20);
> 
>  Put(stackOfInt.pop(i));            <------------- error!!!

First call the Pop *procedure*, which will put its result in I.
Then print I.  I recommend using 'Image, rather than
Text_IO.Integer_IO, to do the formatting.

- Bob




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

* Re: How can i print the element poped from a generic STACK
  2000-11-07  0:00 How can i print the element poped from a generic STACK jordan
@ 2000-11-07  0:00 ` Steve Folly
  2000-11-07  0:00 ` Robert A Duff
  2000-11-07  0:00 ` Larry Hazel
  2 siblings, 0 replies; 4+ messages in thread
From: Steve Folly @ 2000-11-07  0:00 UTC (permalink / raw)


On Tue, 07 Nov 2000 21:43:04 +0800, jordan <huikeith@hotmail.com>
wrote:

>Dear all,
>i want to ask that how can i print the element poped from a generic
>STACK.
>i have write the following code:
>=====================================================
>with TEXT_IO;
>use TEXT_IO;
>
>procedure sample is
>
>generic
> SIZE : POSITIVE;
> type ITEM is private;
>package STACK is
> procedure PUSH(E : in ITEM);
> procedure POP (E : out ITEM);
>end STACK;
>
>package body STACK is
> type TABLE is array (POSITIVE range <>) of ITEM;
> SPACE : TABLE(1..SIZE);
> INDEX : NATURAL := 0;
>
> procedure PUSH(E : in ITEM) is
> begin
>  INDEX := INDEX + 1;
>  SPACE(INDEX) := E;
> end PUSH;
>
> procedure POP(E : out ITEM) is
> begin
>  E := SPACE(INDEX);
>  INDEX := INDEX - 1;
> end POP;
>end STACK;
>
> package stackOfInt is new STACK(100, INTEGER);
> use stackOfInt;
>
> package INT_IO is new TEXT_IO.INTEGER_IO(INTEGER);
> use INT_IO;
>
> i : Integer;
>
>begin
>
>
> stackOfInt.push(20);
>
> Put(stackOfInt.pop(i));            <------------- error!!!
>
>end sample;
>
>==============================================
>i want to print the element of integer 20 on the screen, how can i do??
>is my implementation wrong???
>


What was the error message? Usually these are very informative and in
this case will probably indicate exactly what the problem is.


-- 
Regards,
Steve Folly.




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

* Re: How can i print the element poped from a generic STACK
  2000-11-07  0:00 How can i print the element poped from a generic STACK jordan
  2000-11-07  0:00 ` Steve Folly
  2000-11-07  0:00 ` Robert A Duff
@ 2000-11-07  0:00 ` Larry Hazel
  2 siblings, 0 replies; 4+ messages in thread
From: Larry Hazel @ 2000-11-07  0:00 UTC (permalink / raw)


The procedore pop is a procedure.  It does not return a value.  You tried to
call it as a function.

Larry

jordan wrote:
> 
> Dear all,
> i want to ask that how can i print the element poped from a generic
> STACK.
> i have write the following code:
> =====================================================
> with TEXT_IO;
> use TEXT_IO;
> 
> procedure sample is
> 
> generic
>  SIZE : POSITIVE;
>  type ITEM is private;
> package STACK is
>  procedure PUSH(E : in ITEM);
>  procedure POP (E : out ITEM);
> end STACK;
> 
> package body STACK is
>  type TABLE is array (POSITIVE range <>) of ITEM;
>  SPACE : TABLE(1..SIZE);
>  INDEX : NATURAL := 0;
> 
>  procedure PUSH(E : in ITEM) is
>  begin
>   INDEX := INDEX + 1;
>   SPACE(INDEX) := E;
>  end PUSH;
> 
>  procedure POP(E : out ITEM) is
>  begin
>   E := SPACE(INDEX);
>   INDEX := INDEX - 1;
>  end POP;
> end STACK;
> 
>  package stackOfInt is new STACK(100, INTEGER);
>  use stackOfInt;
> 
>  package INT_IO is new TEXT_IO.INTEGER_IO(INTEGER);
>  use INT_IO;
> 
>  i : Integer;
> 
> begin
> 
>  stackOfInt.push(20);
> 
>  Put(stackOfInt.pop(i));            <------------- error!!!
> 
> end sample;
> 
> ==============================================
> i want to print the element of integer 20 on the screen, how can i do??
> is my implementation wrong???




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

end of thread, other threads:[~2000-11-07  0:00 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-11-07  0:00 How can i print the element poped from a generic STACK jordan
2000-11-07  0:00 ` Steve Folly
2000-11-07  0:00 ` Robert A Duff
2000-11-07  0:00 ` Larry Hazel

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