Write a program to implement linked lists to handle large integers. Since we cannot store big integers in any of the primitive types, the only way is to manage each digit as a node in the linked list. Take care that the index starts at the rightmost side of the string. Therefore, depending on the length of the large integer, the digit at index 0 is the least significant digit of the large integer. A visualization of a typical integer say 1,234,567,890 is as follows: String 1 2 3 4 5 6 7 8 9 0 Index           Therefore, to represent two such numbers for the purpose of adding & subtracting them, we need 2 similar linked lists, each list storing the numbers individually. To create the list, you have to read the large integer as a string. This is because reading the number as an integer or long type would not be possible as they are not enough to store the large integer. After having the large integer as a string, extract each number and store as them into the list. Adding and Subtracting Big Integers After you have the two large integers stored as lists, you can proceed to write the code for adding and subtracting large integers. Since adding and subtracting is a commonly used routine, create the operations in 2 separate functions. The functions should take in 2 operands as list objects, and return a 3rd list object containing the result. The algorithm for adding is as follows: For each object in list do If list contains object at index i for both lists add integers stored in the 2 objects and carry value set carry to 0 If result > 10 set carry to 1 minus 10 from result EndIf insert result in new list Else add integer stored in longer list to carry insert result in new list EndIf End for The algorithm for subtracting is as follows: For each object in list do If list contains object at index i for both lists subtract carry from first integer set carry to 0 If first integer < second integer
set carry to 1 add 10 to first integer EndIf subtract second integer from first integer insert result in new list Else subtract carry from first integer insert result in new list EndIf End for The above algorithms only serve as a guide and do not work for all cases. Hence, you need to enhance the algorithms to ensure that the addition and subtraction works well for all cases. Specifications Your program will prompt the user to enter the name of a text file, computes the addition or subtraction of large integers and display the results on screen. As an illustration, suppose the input text file (test.txt) consists of the following data: 12345678901234567890 + 987654321 12345678901234567890 - 987654321 567 + 123 567 - 12 : Your program shall display the following output: 12345678901234567890 + 987654321 = 12345678902222222211 12345678901234567890 - 987654321 = 12345678900246913569 567 + 123 = 690 567 - 12 = 555 : Additional Notes: o Program must be able to accept operands of varying length in the text file. o For subtraction, if operand 1 is smaller than operand 2, you are to compute accordingly, e.g. 7 - 9 = -2
> Write a program to implement linked lists to handle large integers. Good for you, come back when you've made an effort. And read this ... > Good challenge n happy coding! Or just go away and fail the course. You're simply not up to completing it. This is just a gentle stroll through the foothills, you haven't even seen the mountains yet.
> Good challenge n happy coding! Or just go away and fail the course. You're simply not up to completing it. This is just a gentle stroll through the foothills, you haven't even seen the mountains yet.
Instead try to get numeric value from it and manipulate it because you want to build a calculator remember?
what i read from book is that list is a kinda object that consist of a group of object in the same type.Since i have to store the data as string (ohter type is just not enough to store large integer). How do i convert the element to integer digit by digit and calculate them and convert back to string ? Does index play a role here? how to use it ?i just dont know where to start
This is almost like a Implementation that I have made a few days ago. Though My Objective was not on Addition and Subtraction But Multiplication of Large Positive Integers.
mimio, For doing this , I think the main objective here is to teach addition or subtraction to the computer.
Just think about How Humans Add Or Subtract Numbers.
for example : 2350 +1345 --------- 3695 ---------
Now what will our objective be?
First we need to get in the number from input. -Then put each character into your list.
That would do the input part.
Now when it comes to Addition we will need to add The corresponding digits from the end of the loop. You will also need to find a way for handling values above 10 once 2 corresponding digits are added.