Question: can you d o the same program using this code: import java.util.ArrayList; public class LinkedGrid { private int numRows; private int numCols; private GridNode head;
can you the same program using this code: import java.util.ArrayList;
public class LinkedGrid
private int numRows;
private int numCols;
private GridNode head;
private GridNode lastRowHead;
private GridNode lastColHead;
public LinkedGrid
A constructor which takes the initial number of rows and columns of
the LinkedGrid. This constructor needs to initialize the LinkedGrid with
grid nodes which are initially empty
Example: if I invoked the constructor with new LinkedGrid then I
would have to initialize my LinkedGrid of empty nodes with rows and
nodes per row
public LinkedGridint numRows, int numCols
TO DO
Constructor which takes a normal D array as an argument. This is the
ONLY place you can use a D array and this D array is only used to
initialize the values of your LinkedGrid object
public LinkedGridE elements
TO DO
Get the number of rows
public int getNumRows
return numRows;
Get the number of columns
public int getNumCols
return numCols;
Returns the item at the given row col NOTE: You must return the
item stored in the GridNode, NOT the GridNode itself
public E getint row, int col
TO DO
return null;
Assigns the given item to the GridNode at position row col
public void setint row, int col, E value
TO DO
Get row at index. NOTE: This is not an arraylist of nodes, but of
the values in the nodes.
public ArrayList getRowint index
TO DO
return null;
Get column at index. NOTE: This is not an arraylist of nodes, but of
the values in the nodes.
public ArrayList getColint index
TO DO
return null;
Adds a new row of empty nodes to the beginning of the list
public void addFirstRow
TO DO
Adds a new column of empty nodes to the beginning of the list
public void addFirstCol
TO DO
Adds a new row of empty nodes to the end of the list
public void addLastRow
TO DO
Adds a new column of empty nodes to the end of the list
public void addLastCol
TO DO
Inserts a row at the given index. Insert here means the rows
shift over by from the insertion point onward
public void insertRowint index
TO DO
Inserts a column at the given index. Insert here means the columns
shift over by from the insertion point onward
public void insertColint index
TO DO
Removes the first row
public void deleteFirstRow
TO DO
Removes the first column
public void deleteFirstCol
TO DO
Removes the last row
public void deleteLastRow
TO DO
Removes the last column
public void deleteLastCol
TO DO
Removes the row at the given index
public void deleteRowint index
TO DO
Removes the column at the given index
public void deleteColint index
TO DO
void display
if head null
System.out.printlnThis instance of LinkedGrid is empty.";
return;
GridNode currRow head;
whilecurrRow null
GridNode curr currRow;
whilecurr null
System.out.printfs curr.getElementtoString;
curr curr.nextCol;
System.out.println;
currRow currRow.nextRow;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
