Skip to content

Peek function does not return generic parameter, as it should #305

Open
@BSteffaniak

Description

@BSteffaniak
package "nova/datastruct/list"

class Stack<E> {
    visible Int size

    ListNode<E> top

    visible Bool empty => size <= 0

    public push(E data) {
        ListNode<E> node = new ListNode(data)

        node.next = top
        top       = node

        size++
    }

    public pop() -> E {
        if (empty) {
            throw new EmptyStackException()
        }

        E data = top.data

        top = top.next

        size--

        return data
    }

    public peek() => empty ? null : top.data
}

Metadata

Metadata

Assignees

Type

No type

Projects

Status

No status

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions