Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I only wants an algorithm or pseudo-code for this. Write a program called PlusMinus in Java that reads a text file, in.txt, that contains a

I only wants an algorithm or pseudo-code for this.

Write a program called PlusMinus in Java that reads a text file, in.txt, that contains a list of positive integers (duplicate are possible) separated by spaces and/or line breaks. Zero is not included. After reading the integers, the program saves them in a singly linked list in the same order in which they appear in the input file. Then, without changing the linked list, the program prints out Yes if it is possible to place plus or minus signs in front of each positive integer (including the first one) in the list so that the resulting arithmetic expression equals one of the positive integers in the original list. Otherwise, the program must print out No. Assume that in.txt is in the same folder as your java files and that it contains at least one positive integer.

Only one singly linked list should be used. No additional data structures like array, arraylist or another linked list in program.

Example:

If in.txt contains 1, the program must print out Yes. The expression is +1 and it equals the only one positive integer in the list, 1.

If in.txt contains 7 1 5 2, the program must print out Yes. The expression is +7+1-5+2 and it equals 5. There is another solution: +7+1-5-2 equals 1. Since the goal of the program is to find if there is at least one solution, the program must stop and print Yes after it finds the first solution.

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_2

Step: 3

blur-text-image_3

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

Oracle Database 19c DBA By Examples Installation And Administration

Authors: Ravinder Gupta

1st Edition

B09FC7TQJ6, 979-8469226970

More Books

Students also viewed these Databases questions

Question

What is the Definition for Third Normal Form?

Answered: 1 week ago

Question

Provide two examples of a One-To-Many relationship.

Answered: 1 week ago