NumberStream provides one digit (in character) for every read() call. At the end, it returns -1.
For example, with a number 12345 and the corresponding numberstream object ns, calling ns.read() 6 times yields
'1', '2', '3', '4', '5', -1
Once you read the numbers, you cannot go back to the head of the stream.
Based on two number stream ns1 and ns2, design a function that compares two numbers:
int comp(NumberStream ns1, NumberStream ns2);
return 1 if (ns1 > ns2)
return -1 if (ns2 > ns1)
return 0 if (ns1 == ns2)NumberStream might be in scientific notation (e.g., 123E35, or 12E30). The value after E is reasonably small to be included in a single integer. No '.' and '-' in the number.
Solve it with O(1) memory space.