Answered step by step
Verified Expert Solution
Question
1 Approved Answer
How do I turn this function: private int makeForwardConnections(Model model) { int w = model.width(), h = model.height(); int result; result = 1; for (Sq
How do I turn this function:
private int makeForwardConnections(Model model) { int w = model.width(), h = model.height(); int result; result = 1; for (Sq sq : model) { Sq found; found = null; int nFound; nFound = 0; if (sq.successor() == null && sq.direction() != 0) { PlaceList successors = sq.successors(); if (successors == null) { continue; } for (Place p : successors) { if (sq.connectable(model.get(p))) { ++nFound; found = model.get(p); } } if (sq.sequenceNum() != 0) { for (Place p : successors) { Sq next = model.get(p); if (sq.connectable(next) && next.sequenceNum() != 0) { nFound = 1; found = next; break; } } } if (nFound == 0) { return 0; } else if (nFound == 1) { sq.connect(found); result = 2; } } } return result; }
into two separate functions? :
static Sq findUniqueSuccessor(Model model, Sq start) {
// Your Code Here
static boolean makeForwardConnections(Model model) { int w = model.width(), h = model.height(); boolean result; result = false; for (Sq sq : model) { if (sq.successor() == null && sq.direction() != 0) { Sq found = findUniqueSuccessor(model, sq); if (found != null) { sq.connect(found); result = true; } } } return result; }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started