-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Lecture "Brute-force argorithms", exercise 2 #17
Comments
|
|
from collections import deque def test_stack_from_list(input_list, expected): def stack_from_list(input_list): print(test_stack_from_list(list(["1", "2", "3"]), deque(["1", "2", "3"]))) |
|
def test_stack_from_list(input_list, expected):
result = stack_from_list(input_list)
if expected == result:
return True
else:
return False
from collections import deque
def stack_from_list(input_list):
output_stack = deque()
for item in input_list:
output_stack.append(item)
return output_stack
print(test_stack_from_list([],deque()))
print(test_stack_from_list([0,1,2,3], deque([0,1,2,3]))) |
from collections import deque
# Test case for the algorithm
def test_stack_from_list(input_list, expected):
result = stack_from_list(input_list)
if expected == result:
return True
else:
return False
def stack_from_list(input_list):
output_stack = deque() # the stack to create
# Iterate each element in the input list and add it to the stack
for item in input_list:
output_stack.append(item)
return output_stack
book_list = ["Perturbamento", "La fornace", "Correzione", "Il nipote di Wittengstein", "Il soccombente", "A colpi d'ascia", "Antichi Maestri", "Estinzione"]
book_stack = deque(["Perturbamento", "La fornace", "Correzione", "Il nipote di Wittengstein", "Il soccombente", "A colpi d'ascia", "Antichi Maestri", "Estinzione"])
print(test_stack_from_list(book_list, book_stack)) # A case in point
print(test_stack_from_list([], deque([]))) # Empty list
print(test_stack_from_list([1], deque([1]))) # List of one item |
|
from collections import deque def test_stack_from_list(input_list, expected_output_stack) print(test_stack_from_list(["gemini", "virgo", "libra"], deque(["gemini", "virgo", "libra"])) print(test_stack_from_list([1, 2, 3, 4), deque([1, 2, 3, 4])) |
|
|
|
# test function to create a stack from a list
def test_stack_from_list(input_list, expected):
result = stack_from_list(input_list)
if result == expected:
return True
else:
return False
from collections import deque
# function to create a stack from a list
def stack_from_list(input_list):
output_stack = deque()
# for-each loop execution
for item in input_list:
output_stack.append(item)
return output_stack
# test run
print(test_stack_from_list(list(["Ciao", "Sono", "Giorgia"]), deque(["Ciao", "Sono", "Giorgia"]))) output: True |
Create a test case for the algorithm introduced in Listing 2.
The text was updated successfully, but these errors were encountered: