comp.lang.ada
 help / color / mirror / Atom feed
* HELP : linked lists in ADA
@ 1996-11-26  0:00 Richard Clavelier
  1996-11-30  0:00 ` Vincent Celier
  0 siblings, 1 reply; 2+ messages in thread
From: Richard Clavelier @ 1996-11-26  0:00 UTC (permalink / raw)



  Hello,

We have to create a forward and backward linked list in Ada.

We have the following program (simplified here) :
---------------------------------------------------------------------------

task type CELL is
   entry X_IN (in_v : in INTEGER);
   entry Y_OUT;
end CELL;

type CELLULE is
record
  T : CELL;
end record;

type CELLPOINTER is access CELLULE;

task body CELL is
  forwardLink : CELLPOINTER;
  backwardLink : CELLPOINTER;
begin
[...]
	forwardLink := new CELLULE;
	  -- we should give the new cell a pointer to "this"
	-- backwardLink := a pointer to the previous cell
[...]
end CELL;
---------------------------------------------------------------------------

We have no problem for the forward link, but for the backward link, we
need to know the reference of the current
task ("Current" in Eiffel, "this" in C++), to be able to pass it to the task
that we create...

Does anyone know the solution ? HELP !!!

	Richard

PS: We don't want an object oriented solution.






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

* Re: HELP : linked lists in ADA
  1996-11-26  0:00 HELP : linked lists in ADA Richard Clavelier
@ 1996-11-30  0:00 ` Vincent Celier
  0 siblings, 0 replies; 2+ messages in thread
From: Vincent Celier @ 1996-11-30  0:00 UTC (permalink / raw)



Richard Clavelier wrote:
> 
>   Hello,

I believe you may be one of these students that posts to the whole earth
for getting help on an assignment.

However, the problem is interesting for other people: how to make a
double
linked list of tasks.

> We have to create a forward and backward linked list in Ada.
> 
> We have the following program (simplified here) :
> ---------------------------------------------------------------------------

-- added declarations
type CELLULE;
type CELLPOINTER is access CELLULE;

> 
> task type CELL is
     -- added entry
     entry GET_LINKS (MYSELF : in CELLPOINTER;
                      PREVIOUS : in CELLPOINTER);
>    entry X_IN (in_v : in INTEGER);
>    entry Y_OUT;
> end CELL;
> 
> type CELLULE is
> record
>   T : CELL;
> end record;
> 
-- remove the following declaration
> type CELLPOINTER is access CELLULE;
> 
> task body CELL is
-- add the following declaration
    currentLink : CELLPOINTER;
>   forwardLink : CELLPOINTER;
>   backwardLink : CELLPOINTER;
> begin
-- Add the following statements at the beginning
      accept GET_LINKS (MYSELF : in CELLPOINTER;
                        PREVIOUS : in CELLPOINTER) do
         currentLink := MYSELF;
         backwardLink := PREVIOUS;
      end;
> [...]
>         forwardLink := new CELLULE;
-- add the following statement
          forwardLink.T.GET_BACKWARD_LINK (MYSELF => ForwardLink,
                                           PREVIOUS => currentLink);
>           -- we should give the new cell a pointer to "this"
>         -- backwardLink := a pointer to the previous cell
> [...]
> end CELL;
> ---------------------------------------------------------------------------
> 
> We have no problem for the forward link, but for the backward link, we
> need to know the reference of the current
> task ("Current" in Eiffel, "this" in C++), to be able to pass it to the task
> that we create...
> 
> Does anyone know the solution ? HELP !!!
> 
>         Richard
> 
> PS: We don't want an object oriented solution.

The solution I just exposed is not OO at all!

-- Vincent Celier,
-- 9100 McCutcheon Place, RICHMOND, B.C.
-- CANADA, V7A 5A5
-- +1 (604) 241-9811




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

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

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1996-11-26  0:00 HELP : linked lists in ADA Richard Clavelier
1996-11-30  0:00 ` Vincent Celier

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