Question: 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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!