Files
Exercism/julia/elyses-enchantments/elyses-enchantments.jl

51 lines
1.1 KiB
Julia

function get_item(stack, position)
if position < 1 || position > length(stack)
error("Position out of bounds")
end
return stack[position]
end
function set_item!(stack, position, replacement_card)
if position < 1 || position > length(stack)
error("Position out of bounds")
end
stack[position] = replacement_card
return stack
end
function insert_item_at_top!(stack, new_card)
push!(stack, new_card)
return stack
end
function remove_item!(stack, position)
if position < 1 || position > length(stack)
error("Position out of bounds")
end
deleteat!(stack, position)
end
function remove_item_from_top!(stack)
if isempty(stack)
error("Stack is empty")
end
return deleteat!(stack, length(stack))
end
function insert_item_at_bottom!(stack, new_card)
pushfirst!(stack, new_card)
return stack
end
function remove_item_at_bottom!(stack)
if isempty(stack)
error("Stack is empty")
end
popfirst!(stack)
return stack
end
function check_size_of_stack(stack, stack_size)
return length(stack) == stack_size
end