request for a stack class.

387 views
Skip to first unread message

chl

unread,
Oct 25, 2012, 6:50:09 AM10/25/12
to mi...@dartlang.org
The standard library have most of the abstract data types. So why not add a stack class as well?

Lasse R.H. Nielsen

unread,
Oct 25, 2012, 7:23:44 AM10/25/12
to mi...@dartlang.org
On Thu, Oct 25, 2012 at 12:50 PM, chl <chiah...@gmail.com> wrote:
The standard library have most of the abstract data types. So why not add a stack class as well?

I think we have omitted it so far because you can simply use a List with the "add", "isEmpty" and "removeLast" methods.
Are there any special features you would want from a Stack datatype?

/L
--
Lasse R.H. Nielsen - l...@google.com  
'Faith without judgement merely degrades the spirit divine'
Google Denmark ApS - Frederiksborggade 20B, 1 sal - 1360 København K - Denmark - CVR nr. 28 86 69 84

chl

unread,
Oct 25, 2012, 7:45:08 AM10/25/12
to mi...@dartlang.org
I want a stack class mainly to make the intent of my code clearer. To essentially capture the LIFO behaviour. 

And one more question, why is the queue implemented using a doubly linked list and not a circular linked list.

Ladislav Thon

unread,
Oct 25, 2012, 7:53:47 AM10/25/12
to mi...@dartlang.org
I want a stack class mainly to make the intent of my code clearer. To essentially capture the LIFO behaviour. 

And one more question, why is the queue implemented using a doubly linked list and not a circular linked list.

So that you can use Queue as a Stack :-)

I know I already did.

LT

chl

unread,
Oct 25, 2012, 7:57:39 AM10/25/12
to mi...@dartlang.org
Thats where i find dart's Queue to be most strange. There is really no reason for a queue if you can't capture the FIFO behaviour yes?

Ladislav Thon

unread,
Oct 25, 2012, 8:14:52 AM10/25/12
to mi...@dartlang.org

Thats where i find dart's Queue to be most strange. There is really no reason for a queue if you can't capture the FIFO behaviour yes?

But you can. And you can do it with plain old List too.

The only difference is that List works more like an array, while Queue is a linked list.

LT

chl

unread,
Oct 25, 2012, 8:23:33 AM10/25/12
to mi...@dartlang.org
I think if that were the case wouldn't there be significant overlap between a queue and a doubly linked list.

But the idea of a queue and stack is to capture a subset of the abilities of a list to represent FIFO and LIFO. The ability for a queue to perform LIFO is actually contradictory to my understanding.

Since we can perform both FIFO and LIFO on the current Queue wouldn't it be more appropriate to rename it as a Deque instead.

Ladislav Thon

unread,
Oct 25, 2012, 9:13:16 AM10/25/12
to mi...@dartlang.org
Since we can perform both FIFO and LIFO on the current Queue wouldn't it be more appropriate to rename it as a Deque instead.

Agree, that would really be much better. Or just LinkedList, but that name is too long :-)

LT

Lasse R.H. Nielsen

unread,
Oct 25, 2012, 9:58:11 AM10/25/12
to mi...@dartlang.org
On Thu, Oct 25, 2012 at 3:13 PM, Ladislav Thon <lad...@gmail.com> wrote:
Since we can perform both FIFO and LIFO on the current Queue wouldn't it be more appropriate to rename it as a Deque instead.

Agree, that would really be much better. Or just LinkedList, but that name is too long :-)

Not really, but it suggests that it's actually a List, which it isn't. Lists in Dart are intended for random access, and we should keep it that way.

Personally I dislike cute abbreviations like "Deque" - it's a DoubleEndedQueue - and you can understand that without knowing the abbreviation.

chl

unread,
Oct 25, 2012, 10:04:25 AM10/25/12
to mi...@dartlang.org
That is easier to understand, if you can read english that is. 

Btw, i didn't know Deque is an abbreviation for "DoubleEndedQueue". Thank you :)

Ladislav Thon

unread,
Oct 25, 2012, 10:38:32 AM10/25/12
to mi...@dartlang.org


> Not really, but it suggests that it's actually a List, which it isn't. Lists in Dart are intended for random access, and we should keep it that way.

Fair enough. If it implemented List, it would have to have the [] operator, which should really be O(1), and if it didn't implement List, it would be weird if it was called LinkedList.

On the other hand, it really _is_ a linked list, not only a queue (or double ended queue, for that matter). And "linked list" is a common name and noone expect those to support random access.

LT

Reply all
Reply to author
Forward
0 new messages