Some solutions for the julia path
This commit is contained in:
50
julia/elyses-enchantments/elyses-enchantments.jl
Normal file
50
julia/elyses-enchantments/elyses-enchantments.jl
Normal file
@@ -0,0 +1,50 @@
|
||||
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
|
||||
Reference in New Issue
Block a user