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 do 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(2,3), then I
would have to initialize my LinkedGrid of 6 empty nodes with 2 rows and
3 nodes per row
*/
public LinkedGrid(int numRows, int numCols){
// TO DO
}
/*
Constructor which takes a normal 2D array as an argument. This is the
ONLY place you can use a 2D array and this 2D array is only used to
initialize the values of your LinkedGrid object
*/
public LinkedGrid(E[][] 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 get(int row, int col){
// TO DO
return null;
}
/*
Assigns the given item to the GridNode at position (row, col)
*/
public void set(int 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 getRow(int 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 getCol(int 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 1 from the insertion point onward)
*/
public void insertRow(int index){
// TO DO
}
/*
Inserts a column at the given index. (Insert here means the columns
shift over by 1 from the insertion point onward)
*/
public void insertCol(int 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 deleteRow(int index){
// TO DO
}
/*
Removes the column at the given index
*/
public void deleteCol(int index){
// TO DO
}
void display(){
if (head == null){
System.out.println("This instance of LinkedGrid is empty.");
return;
}
GridNode currRow = head;
while(currRow != null){
GridNode curr = currRow;
while(curr != null){
System.out.printf("%5s ", curr.getElement().toString());
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 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 Accounting Questions!