Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN: 9780133594140
Author: James Kurose, Keith Ross
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Question
from time import sleep
from os import system
class Node:
def__init__(self, data):
self.data=data
self.next=None
class Stack:
def__init__(self):
self.top=None
defpush(self, data):
new_node=Node(data)
ifself.topisNone:
self.top=new_node
else:
new_node.next=self.top
self.top=new_node
defpop(self):
ifself.topisNone:
returnNone
data=self.top.data
self.top=self.top.next
returndata
def dfs(maze, start, end):
rows=len(maze)
cols=len(maze[0])
visited= [[Nonefor_inrange(cols)] for_inrange(rows)]
stack=Stack()
stack.push(start)
visited[start[0]][start[1]] =start
whilestack.top:
current=stack.pop()
ifcurrent==end:
current=visited[current[0]][current[1]] # Retrocede un paso desde el final
whilecurrent!=start:
ifcurrent!=end: # No reemplace la meta "B" con un punto
maze[current[0]][current[1]] ='.'
current=visited[current[0]][current[1]]
print('\n'.join(''.join(row) forrowinmaze)) # Imprime el laberinto final
returnTrue# Termina la ejecución tan pronto como se encuentra el estado objetivo
row, col=current
fordr, dcin [(1, 0), (-1, 0), (0, 1), (0, -1)]:
new_row, new_col=row+dr, col+dc
if (0<=new_row<rowsand0<=new_col<colsand
visited[new_row][new_col] isNoneand
maze[new_row][new_col] !='#'):
stack.push((new_row, new_col))
visited[new_row][new_col] =current
if (new_row, new_col) !=end: # No reemplace la meta "B" con un punto
maze[new_row][new_col] ='.'
print('\n'.join(''.join(row) forrowinmaze)) # Imprime el laberinto
sleep(0.5) # Pausa por un segundo
system("clear")
returnFalse
def read_maze_from_file(filename):
maze= []
start=end=None
withopen(filename, 'r') asfile:
fori, lineinenumerate(file):
row=list(line.rstrip().replace('\t', ' '))
if'A'inrow:
start= (i, row.index('A'))
if'B'inrow:
end= (i, row.index('B'))
maze.append(row)
returnmaze, start, end
maze, start, end = read_maze_from_file('maze22.txt')
if dfs(maze, start, end):
print("Path found from start to end")
Please stop inserting points in the next maze, which is a txt file, when you find the letter B.
maze22.txt
### #########
# ################### # #
# #### # # # #
# ################### # # # #
# # # # #
##################### # # # #
# ## # # # #
# # ## ### ## ######### # # #
# # # ##B# # # #
# # ## ################ # # #
### ## #### # # #
### ############## ## # # # #
### ## # # # #
###### ######## ####### # # #
###### #### # #
A ######################
# ################### # #
# #### # # # #
# ################### # # # #
# # # # #
##################### # # # #
# ## # # # #
# # ## ### ## ######### # # #
# # # ##B# # # #
# # ## ################ # # #
### ## #### # # #
### ############## ## # # # #
### ## # # # #
###### ######## ####### # # #
###### #### # #
A ######################
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by stepSolved in 2 steps
Knowledge Booster
Similar questions
- Looking for output HONORS COUNT : 2arrow_forwardpublic class OfferedCourse extends Course { // TODO: Declare private fields // TODO: Define mutator methods - // setInstructorName(), setLocation(), setClassTime() // TODO: Define accessor methods - // getInstructorName(), getLocation(), getClassTime() } import java.util.Scanner; public class CourseInformation { public static void main(String[] args) { Scanner scnr = new Scanner(System.in); Course myCourse = new Course(); OfferedCourse myOfferedCourse = new OfferedCourse(); String courseNumber, courseTitle; String oCourseNumber, oCourseTitle, instructorName, location, classTime; courseNumber = scnr.nextLine(); courseTitle = scnr.nextLine(); oCourseNumber = scnr.nextLine(); oCourseTitle = scnr.nextLine(); instructorName = scnr.nextLine(); location = scnr.nextLine(); classTime = scnr.nextLine(); myCourse.setCourseNumber(courseNumber); myCourse.setCourseTitle(courseTitle);…arrow_forwardpython: class Student:def __init__(self, first, last, gpa):self.first = first # first nameself.last = last # last nameself.gpa = gpa # grade point average def get_gpa(self):return self.gpa def get_last(self):return self.last class Course:def __init__(self):self.roster = [] # list of Student objects def add_student(self, student):self.roster.append(student) def course_size(self):return len(self.roster) # Type your code here if __name__ == "__main__":course = Course()course.add_student(Student('Henry', 'Nguyen', 3.5))course.add_student(Student('Brenda', 'Stern', 2.0))course.add_student(Student('Lynda', 'Robison', 3.2))course.add_student(Student('Sonya', 'King', 3.9)) student = course.find_student_highest_gpa()print('Top student:', student.first, student.last, '( GPA:', student.gpa,')')arrow_forward
- 8. Following is the node class: class node { int v node *next: public: node(int x) {v=x; next3D03;} friend class list: }3; Implement the sequential list class below: class list { // circular list class // head position node *head; public: bool empty() { return !head;} list() {head-0;} ~list(); void add(int x); int get(); // empty list judgment / constructor // destructor, to be implemented // add to tail, to be implemented // get from head, to be implemented }3Barrow_forwardJava Programing Design class CarInLine, with the following specifications: The class has two instance variables: arrivalTime and DepartureTime, stored as integers. Define a constructor that accepts an integer as an argument representing the arrival time, in which you set the departure time to zero, marking the beginning of a simulation. Create an appropriate set and get methods for the two instance variables. Implement a method totalTime() that returns an integer value representing the time spent in the queue, as the difference between the departure time and the arrival time. Define ten queues, simulating the functionality of the process, increasing the number of cashiers from one, and collecting the average waiting time for each scenario. Each simulation will work with the same number of cars, which is considered 100. The maximum number of cashiers/toll booths is 10. Create the queue with link-based implementation. Create each queue with the corresponding number of cashiers,…arrow_forwardDraw a UML class diagram for the following code: class Node: def __init__(self, value): self.value = value self.next = None class Stack: def __init__(self): self.top = None def isEmpty(self): return self.top is None def push(self, item): new_node = Node(item) new_node.next = self.top self.top = new_node def pop(self): if self.isEmpty(): raise Exception("Stack is empty") popped_item = self.top.value self.top = self.top.next return popped_item def popAll(self): items = [] while not self.isEmpty(): items.append(self.pop()) return items[::-1] def peek(self): if self.isEmpty(): raise Exception("Stack is empty") return self.top.value # Verificationstack = Stack()print("Is stack empty?", stack.isEmpty()) stack.push(10)stack.push(20)stack.push(30)print("Top item:", stack.peek()) print("Popped item:", stack.pop())print("Popped…arrow_forward
arrow_back_ios
arrow_forward_ios
Recommended textbooks for you
- Computer Networking: A Top-Down Approach (7th Edi...Computer EngineeringISBN:9780133594140Author:James Kurose, Keith RossPublisher:PEARSONComputer Organization and Design MIPS Edition, Fi...Computer EngineeringISBN:9780124077263Author:David A. Patterson, John L. HennessyPublisher:Elsevier ScienceNetwork+ Guide to Networks (MindTap Course List)Computer EngineeringISBN:9781337569330Author:Jill West, Tamara Dean, Jean AndrewsPublisher:Cengage Learning
- Concepts of Database ManagementComputer EngineeringISBN:9781337093422Author:Joy L. Starks, Philip J. Pratt, Mary Z. LastPublisher:Cengage LearningPrelude to ProgrammingComputer EngineeringISBN:9780133750423Author:VENIT, StewartPublisher:Pearson EducationSc Business Data Communications and Networking, T...Computer EngineeringISBN:9781119368830Author:FITZGERALDPublisher:WILEY
Computer Networking: A Top-Down Approach (7th Edi...
Computer Engineering
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:PEARSON
Computer Organization and Design MIPS Edition, Fi...
Computer Engineering
ISBN:9780124077263
Author:David A. Patterson, John L. Hennessy
Publisher:Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:9781337569330
Author:Jill West, Tamara Dean, Jean Andrews
Publisher:Cengage Learning
Concepts of Database Management
Computer Engineering
ISBN:9781337093422
Author:Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:Cengage Learning
Prelude to Programming
Computer Engineering
ISBN:9780133750423
Author:VENIT, Stewart
Publisher:Pearson Education
Sc Business Data Communications and Networking, T...
Computer Engineering
ISBN:9781119368830
Author:FITZGERALD
Publisher:WILEY