close
看可讀性高的程式碼請按此

程式碼有點亂,可是跟C++比起來我覺得很簡單了= =

def stack(ary, lvl, max, input)
if lvl < max
ary[lvl] = input
puts "#{input} has been added in the stack!"
lvl+=1
get_element ary
else
puts "Stack is full!!!!"
exit
end

lvl
end

def get_element ary
print "Element in the array:"
ary.each do |x|
print "#{x} "
end
puts
end


puts "Please input a number for the stack max!"
max=gets.to_i
lvl=0
ary={}
puts "Please input elements into the stack, type exit to exit."
arg = gets.chomp
while arg != "exit"
lvl=stack(ary, lvl, max, arg)
arg = gets.chomp
end


目前只有新增的版本
至於刪除嘛... Orz..
還沒有寫@@


arrow
arrow
    全站熱搜

    hechian 發表在 痞客邦 留言(0) 人氣()