Ruby万能数组(包括数组,队列,栈,哈希)

清华大佬耗费三个月吐血整理的几百G的资源,免费分享!....>>>

#万能数组
class AllArray
   def initialize(type)
     if type=="array"
       @items=[]
       def add(element)
         @items<<element
       end
       
       def delete(element)
         @items.delete(element)
       end
       
       def count
         return @items.size
       end
     end
     
     if type=="hash"
       @items=Hash.new
       def add(key,value)
         @items.store(key, value)
       end
       
       def delete_by_key(key)
         if @items.has_key?(key)
           @items.delete(key)
         else
           return "没有这个元素!"
         end
       end
       
       def delete_by_value(value)
         if @items.has_value?(value)
           
         end
       end
     end
     
     if type=="stack"
       @item=[]
       def push(element)
         @item<<element
       end
       
       def pop
         @item.delete_at(@item.size-1)
       end
       
       def count
         return @item.size
       end
     end
     
     if type=="queue"
       @item=[]
       def add(element)
         @item<<element
       end
       
       def kick_out
         @item.delete_at(0)
       end
       
       def count
         return @item.size
       end
     end
   end 
end