From: "Eric Sabo" <sabo@hhs.net>
Subject: Need help with code?
Date: 1997/12/10
Date: 1997-12-10T00:00:00+00:00 [thread overview]
Message-ID: <66m904$naj$1@usenet48.supernews.com> (raw)
Can someone tell what am I doing wrong with this code?
----------------------- begin ----------------------------------------
generic
type item_type is private;
procedure push(x : in out item_type);
procedure push(x : in out item_type) is
type item_node;
type item_ptr is access item_node;
record
item : item_type;
next : item_ptr;
end record;
temp : item_type;
first, last, p : item_ptr := null;
begin
put("Enter data (null to quit)");
get(temp);
while temp /= null loop
p := new item_node;
p.item := temp;
p.next := null;
if first = null then
first := p;
last := p;
else
last.next := p;
last := p;
end if;
put("Enter data (null to quit)");
get(temp);
end loop;
end push;
generic
type item_type is private;
procedure print(x : in out item_type);
procedure print(x : in out item_type) is
type item_node;
type item_ptr is access item_node;
record
item : item_type;
next : item_ptr;
end record;
first, last, p : item_ptr;
begin
put_line("Here is the stack you requested");
p := first;
while p /= null loop
put(p.number);
put(" ");
p := p.next;
end loop;
end print;
generic
type item_type is private;
procedure pop(x : in out item_type);
procedure pop(x : in out item_type) is
type item_node;
type item_ptr is access item_node;
record
item : item_type;
next : item_ptr;
end record;
first, last, p : item_ptr;
begin
put_line("Popping the first item of the linked list");
p := first.next;
first := p;
end pop;
with push;
with pop;
with print;
with gnat.io; use gnat.io;
procedure maingeneric is
-- integer type
type item_integer;
type int_ptr is access item_integer;
record
a : integer;
next : int_ptr;
end record;
procedure int_push is new push(item_integer);
procedure int_pop is new pop(item_integer);
procedure int_print is new print(item_integer);
-- float type
type item_float;
type flt_ptr is access item_float;
record
f : float;
next : flt_ptr;
end record;
procedure flt_push is new push(item_float);
procedure flt_pop is new pop(item_float);
procedure flt_print is new print(item_float);
-- record type
type item_rec;
type rec_ptr is access item_rec;
record
name : string (1..20);
id : string(1..10);
next : rec_ptr;
end record;
procedure rec_push is new push(item_rec);
procedure rec_pop is new pop(item_rec);
procedure rec_print is new print(item_rec);
begin
push(a);
push(f);
push(name);
end maingeneric;
------------------- end --------------------------------
thanks,
Eric Sabo
sabo@hhs.net
sab9074@cup.edu
next reply other threads:[~1997-12-10 0:00 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
1997-12-10 0:00 Eric Sabo [this message]
1997-12-14 0:00 ` Need help with code? Chris Morgan
1997-12-15 0:00 ` Simon Wright
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox