167k views
3 votes
Use the singly linked list class introduced in the lab to implement integers of unlimited size. Each node of the list should store one digit of the integer. You are to implement the addition, subtraction and multiplication operations. Please note that any additional data structure to be used in solving this problem has to be taken from the ones introduced in the ICS 202 lab. In addition, provide a test class that will do the following: It will keep asking the user to enter two integers, choose one of the operations (addition, subtraction, multiplication) and then display the result. The program will stop upon entering the "#" character (without the double quotes).

this singly linked list class:
public class SLL {
private class SLLNode {
private T info;
private SLLNode next;
int value;
public SLLNode() {
this(null, null);
}

1 Answer

3 votes

Final answer:

To implement unlimited size integers using a singly linked list, digits of the integer are stored in separate nodes. Addition, subtraction, and multiplication operations are performed by traversing the lists and applying digit-by-digit arithmetic.

A test class will manage user interaction for operating these functions until the '#' character is entered.

Step-by-step explanation:

The task involves utilizing a singly linked list to represent and manipulate integers of unlimited size in the context of a programming environment. This involves storing each digit of a large integer in separate nodes of the linked list.

For the operations addition, subtraction, and multiplication, you will need to traverse the linked lists that represent the integers, performing digit-by-digit arithmetic in a manner akin to how you would do it by hand.

When carrying out these operations, you will maintain the invariant that digits are stored in reverse order: the least significant digit is at the head of the list, which simplifies the addition and multiplication process.

A test class must be created to interact with the user, read two large numbers, perform the selected operation, and show the result. This interaction continues until the user inputs the "#" character to terminate the process. This practical application of computer science demonstrates how data structures can be used to overcome limitations of primitive data types.

User Chris Magnussen
by
7.9k points