Answered step by step
Verified Expert Solution
Link Copied!

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 1. Store the address of this object in a variable called longLine.
largest =0
for each row i 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 =1
for each column j of the grid starting at the second one and moving to the right do {
if letter at row i and column j 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 j-adjacent +1(Why this column?)
of length adjacent
}
}
else {
letter = letter at row i and column j of the grid
}
adjacent =1
}
// Now scan the columns from left to right; each column is scanned from the bottom to the top
for each column j 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 j
adjacent =1
for each row i of the grid from the second row from the bottom and moving to the top do
if letter at row i and column j 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 j of length adjacent
}
}
else {
letter = letter at row i and column j of the grid
}
adjacent =1
}
if the length of longline is larger than 2 then return longline else return null
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Data Infrastructure For Medical Research In Databases

Authors: Thomas Heinis ,Anastasia Ailamaki

1st Edition

1680833480, 978-1680833485

More Books

Students also viewed these Databases questions

Question

What are Incoterms, and why do firms follow them?

Answered: 1 week ago