This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def empty_into(container) | |
current = @first | |
while current do | |
container << current.value unless current.value == nil | |
self.popFront | |
current = current.next_node | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
while string.include?('gn') | |
string.gsub!("gn", 'ng') | |
end | |
puts string |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if string[i] == '}' || ')' || ']' | |
case string[i] | |
when "]" | |
if s.topFront == "[" | |
s.popFront | |
else | |
return false | |
end | |
when ")" | |
if s.topFront == "(" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
s.pushFront(string[i]) if string[i] == '{' || string[i] == '[' || string[i] == '(' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if s.is_empty? | |
s.pushFront(string[i]) if string[i] == '{' || string[i] == '[' || string[i] == '(' | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def print_stack | |
while @first.next_node | |
print @first.value | |
@first = @first.next_node | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def is_empty? | |
@first.nil? | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def topFront | |
@first.value if unless is_empty? | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def popFront | |
raise "Stack is empty" if is_empty? | |
@first = @first.next_node | |
end |