Method: Liste#eachs

Defined in:
lib/prct06/list.rb

#eachsObject

Tarea 4 - each



140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
# File 'lib/prct06/list.rb', line 140

def eachs
  sorted = [@head.value]
  self.each_with_index do |x, pos_x|
    if (pos_x != 0)
      sorted.each_with_index do |y, pos_y|
        if (pos_y == sorted.size - 1)
          if (x < y)
            sorted.insert(pos_y, x)
            break
          else
            sorted.push(x)
            break
          end
        elsif (x < y)
          sorted.insert(pos_y, x)
          break
        end
      end
    end
  end
  return sorted
end