Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Write me a code in the java lanaguage with these psusedocode instructions, also the only instance variable is: 'private char [ ] [ ] grid;
Write me a code in the java lanaguage with these psusedocode instructions, also the only instance variable is: 'private char grid;
Pseudocode for Algoritnm longestLine
Algorithm longestLine
Scan first the rows of the grid from bottom to top
Create an object of the class Line representing a horizontal line starting at the first row and first column
of grid and of length Store the address of this object in a variable called longLine.
largest
for each row of the grid starting at the bottom and moving to the top do
letter letter at row i and leftmost column of the grid
adjacent
for each column of the grid starting at the second one and moving to the right do
if letter at row i and column of the grid is equal to letter and letter blank space then
increase adjacent
if adjacent is bigger than largest then
largest adjacent
longLine new object of the class Line representing a horizontal line
starting at row i and column adjacent Why this column?
of length adjacent
else
letter letter at row i and column of the grid
adjacent
Now scan the columns from left to right; each column is scanned from the bottom to the top
for each column of the grid starting at the leftmost one and moving to the right do
letter letter at the bottom row of the grid and column
adjacent
for each row of the grid from the second row from the bottom and moving to the top do
if letter at row i and column of the grid is equal to letter and letter blank space then
increase adjacent
if adjacent is bigger than largest then
largest adjacent
longline new object of the class Line representing a vertical line
starting at row i and column of length adjacent
else
letter letter at row i and column of the grid
adjacent
if the length of longline is larger than then return longline else return null
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