On Sat, 23 Nov 2002, Jonathan M. Hollin wrote:

> Can anyone offer me some pointers (pun intended) on how to implement a
> stack in Perl with an array?
The description you give does not describe an 'academic' stack...
You would probably need to read some good Perl books. I suggest 
the "classical" <Programming Perl - Ed. O'Reilly>

> 
> I need to have an array of elements as follows:
> 
> 0 - e1
> 1 - e2
> 2 - e3
> ...
@stack = (e1, e2, e3, ...)

> 
> And I need to be able to insert items:
> 
> e4 needs to go into $array[1].  1 and 2 need to move down (or up or left
> or right - depending on how you visualise arrays) yet retain their contents:
> 
> 0 - e1
> 1 - e4
> 2 - e2
> 3 - e3
splice @stack, 1, 0, e4;
> ...
> 
> And, you guessed it, I need to be able to remove elements, and have the
> others move down...
> 
> remove e2, leaving:
> 
> 0 - e1
> 1 - e4
> 3 - e3
> ...
splice @stack, 2, 1;

Franck.

====================================================
ESSENTIAL SOFTWARE - Ingénierie Informatique
Solutions Linux & Open Source en Polynésie française
----------------------------------------------------
http://www.esoft.pf/
Tél: (689) 562 395 / 541 295

+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
"Fiabilisez vos systèmes informatiques.
 Osez Linux, le choix moderne des gouvernements
 et des entreprises Fortune 500"
====================================================

Reply via email to