CSC148H5 Lecture Notes - Lecture 5: University Of Toronto Mississauga, Priority Queue, Docstring

89 views3 pages

Document Summary

Csc148h5s - introduction to computer science (winter 2017) Write the body of the function below so that it satisfies its docstring. Assume that module stack. py defines a class stack that provides the usual methods: is_empty(), push(item), pop(). Return the number of items on stack s, *without* modifying s. (it"s ok if the contents of s are modified during the execution of this function, as long as everything is restored before the function returns) # hint: you can use more than one stack. Solution 2 total = 0 for items in s: return total. # you can"t access the information like that. You can only check total = total + 1 the top. Solution 3 total = 0 while not s. is_empty(): s. pop() total = total + 1 return total. Returns the directed value but modifies the stack. Solution 4 s1 = stack() s1. push( 4 ) s1. push( 5 ) result = size(s1) print(result) result = size(s1) print(result) #0.

Get access

Grade+
$40 USD/m
Billed monthly
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
10 Verified Answers
Class+
$30 USD/m
Billed monthly
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
7 Verified Answers

Related Documents