[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Drawing the line between speed and simplicity/elegance
- From: Luciano Ramalho <luciano@...>
- Date: Thu, 7 May 2015 15:43:54 -0300
On Thu, May 7, 2015 at 2:57 PM, Brigham Toskin <brighamtoskin@gmail.com> wrote:
>> As long as you can avoid nil, then table.insert() and table.remove()
>> implement a LIFO stack (since both default to the last position). That
>> is:
>>
>> push = table.insert
>> pop = table.remove
>>
>> How much more compilicated is your ADT?
>
>
> This is actually exactly what I was doing, originally. But I have to check
> for underflow for most operations. And nil is a valid value. [...]
Can't you replace nil with another sentinel value when you're about to
push it into the stack?
Cheers,
Luciano
--
Luciano Ramalho
| Author of Fluent Python (O'Reilly, 2015)
| http://shop.oreilly.com/product/0636920032519.do
| Professor em: http://python.pro.br
| Twitter: @ramalhoorg