Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

5.6 Lets try something a little different: a two-dimensional linked list, which well call a matrix. This is the list analogue of a two-dimensional array.

5.6 Lets try something a little different: a two-dimensional linked list, which well call a matrix. This is the list analogue of a two-dimensional array. It might be useful in applications such as spreadsheet programs. If a spreadsheet is based on an array, and you insert a new row near the top, you must move every cell in the lower rows N*M cells, which is potentially a slow process. If the spreadsheet is implemented by a matrix, you need only change N pointers. For simplicity, well assume a singly linked approach (although a double-linked approach would probably be more appropriate for a spreadsheet). Each link (except those on the top row and left side) is pointed to by the link directly above it and by the link on its left. You can start at the upper-left link and navigate to, say, the link on the third row and fifth column by following the pointers down two rows and right four columns. Assume your matrix is created with specified dimensions (7 by 10, for example). You should be able to insert values in specified links and display the contents of the matrix.

You MUST use this MAIN below, you MUST USE!!!!!

public static void main(String[] args) throws IOException

{

int width, height, x, y, value;

putText("Enter the width of the matrix: ");

width = getInt();

putText("Enter the height of the matrix: ");

height = getInt();

Matrix theMatrix = new Matrix(width, height);

while(true)

{

putText("Enter first letter of ");

putText("(d) display, (i) insert, (s) sum, (f) fill: ");

int choice = getChar();

switch(choice)

{

case 'd':

theMatrix.display();

break;

case 'i':

putText("Enter x coordinate: ");

x = getInt();

putText("Enter y coordinate: ");

y = getInt();

putText("Enter value to insert: ");

value = getInt();

theMatrix.insert(x, y, value);

break;

case 's':

theMatrix.sums();

break;

case 'f':

putText("Enter value to fill: ");

value = getInt();

theMatrix.fill(value);

break;

default:

putText("Invalid entry ");

} // end switch

} // end while

} // end main()

// -------------------------------------------------------------

The Output MUST be like this, MUST be like this in format and in form!!! (Do not post answer if it's not like this):

Enter the width of the matrix: 7

Enter the height of the matrix: 10

Enter first letter of (d) display, (i) insert, (s) sum, (f) fill: d

00 10 20 30 40 50 60

01 11 21 31 41 51 61

02 12 22 32 42 52 62

03 13 23 33 43 53 63

04 14 24 34 44 54 64

05 15 25 35 45 55 65

06 16 26 36 46 56 66

07 17 27 37 47 57 67

08 18 28 38 48 58 68

09 19 29 39 49 59 69

Enter first letter of (d) display, (i) insert, (s) sum, (f)fill: i

Enter x coordinate: 3

Enter y coordinate: 5

Enter value to insert: 5

Enter first letter of (d) display, (i) insert, (s) sum, (f) fill: d

00 10 20 30 40 50 60

01 11 21 31 41 51 61

02 12 22 32 42 52 62

03 13 23 33 43 53 63

04 14 24 34 44 54 64

05 15 25 05 45 55 65

06 16 26 36 46 56 66

07 17 27 37 47 57 67

08 18 28 38 48 58 68

09 19 29 39 49 59 69

Enter first letter of (d) display, (i) insert, (s) sum, (f) fill: s

00 10 20 30 40 50 60 210

01 11 21 31 41 51 61 217

02 12 22 32 42 52 62 224

03 13 23 33 43 53 63 231

04 14 24 34 44 54 64 238

05 15 25 05 45 55 65 215

06 16 26 36 46 56 66 252

07 17 27 37 47 57 67 259

08 18 28 38 48 58 68 266

09 19 29 39 49 59 69 273

045 145 245 315 445 545 645

Enter first letter of (d) display, (i) insert, (s) sum, (f) fill: d

00 10 20 30 40 50 60

01 11 21 31 41 51 61

02 12 22 32 42 52 62

03 13 23 33 43 53 63

04 14 24 34 44 54 64

05 15 25 05 45 55 65

06 16 26 36 46 56 66

07 17 27 37 47 57 67

08 18 28 38 48 58 68

09 19 29 39 49 59 69

Enter first letter of (d) display, (i) insert, (s) sum, (f) fill: f

Enter value to fill: 11

Enter first letter of (d) display, (i) insert, (s) sum, (f) fill: d

11 11 11 11 11 11 11

11 11 11 11 11 11 11

11 11 11 11 11 11 11

11 11 11 11 11 11 11

11 11 11 11 11 11 11

11 11 11 11 11 11 11

11 11 11 11 11 11 11

11 11 11 11 11 11 11

11 11 11 11 11 11 11

11 11 11 11 11 11 11

Enter first letter of (d) display, (i) insert, (s) sum, (f) fill:

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 And Databases

Authors: Jeff Mapua

1st Edition

1978502257, 978-1978502253

Students also viewed these Databases questions

Question

What is the relative priority among the viable goals?

Answered: 1 week ago