Skip to content

Instantly share code, notes, and snippets.

View nikasulo's full-sized avatar
🚀
Working Remotely

Nikasulo nikasulo

🚀
Working Remotely
View GitHub Profile
@nikasulo
nikasulo / transposition
Created September 4, 2019 22:20
Empty_into Method
def empty_into(container)
current = @first
while current do
container << current.value unless current.value == nil
self.popFront
current = current.next_node
end
end
@nikasulo
nikasulo / transposition
Created September 3, 2019 23:16
brute force solution
while string.include?('gn')
string.gsub!("gn", 'ng')
end
puts string
@nikasulo
nikasulo / balancing_brackets
Created August 29, 2019 12:33
Switch statement
if string[i] == '}' || ')' || ']'
case string[i]
when "]"
if s.topFront == "["
s.popFront
else
return false
end
when ")"
if s.topFront == "("
@nikasulo
nikasulo / balancing_brackets
Created August 29, 2019 12:30
Push if it is an opening
s.pushFront(string[i]) if string[i] == '{' || string[i] == '[' || string[i] == '('
@nikasulo
nikasulo / balancing_brackets
Created August 29, 2019 12:27
If stack is empty push first character
if s.is_empty?
s.pushFront(string[i]) if string[i] == '{' || string[i] == '[' || string[i] == '('
end
@nikasulo
nikasulo / balancing_brackets
Last active August 28, 2019 23:31
Initialize function
def balanced_brackets?(string)
#Initialize Stack
s = Stack.new
for i in 0...string.length do
#Rest of the code in here
end
#When we come out of the loop, if our stack is not empty, then we have a problem
return false if s.first.next_node
@nikasulo
nikasulo / min-max-stack-tutorial
Created August 28, 2019 20:08
Printing the content of the stack
def print_stack
while @first.next_node
print @first.value
@first = @first.next_node
end
end
@nikasulo
nikasulo / balancing_brackets
Created August 28, 2019 20:07
Balancing brackets tutorial
def is_empty?
@first.nil?
end
@nikasulo
nikasulo / balancing_brackets
Created August 28, 2019 20:06
Balancing brackets tutorial
def topFront
@first.value if unless is_empty?
end
@nikasulo
nikasulo / balancing_brackets
Created August 28, 2019 20:04
Balancing brackets tutorial
def popFront
raise "Stack is empty" if is_empty?
@first = @first.next_node
end