• Post Reply Bookmark Topic Watch Topic
  • New Topic

DLL Long Integers....  RSS feed

 
Justin Fox
Ranch Hand
Posts: 802
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have to create an application that can add and multiply long ints....

but the long ints have to be created with DLL's....

so if you had the LongInt 9876 and 456

the would be stored in 5 and 4 nodes respectively..

////////////////////////////////////////////

head --> 9 ----> 8 ----> 7 ----> 6(null)

head --> 4 ---> 5 ----> 6(null)

///////////////////////////////////////////

but the prof wants the input to look like this..

a
345235791087253
b
78266626262626132057025
c
7807734550782751312308736534500725077878
d
0
e
137199898998898989898989

ok, now my question is....

how do i create a new LongInt list every time they enter the letter

a - b...

i was going to use an LongInt[] to store them all then just sift through
when i go to mult/add.

but if i do this.



this is kinda getting tough, plz help.....

thx,
Justin

oh yes, and how do you convert an int > char, and visa versa?

thx again...
 
Justin Fox
Ranch Hand
Posts: 802
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
plz, help...
 
Campbell Ritchie
Marshal
Posts: 56536
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don't know about your large integer class.
Sorry.

As for converting an int to a char, or a char to an int, please be very specific what you mean.

You don't convert a char to an int. A char is already a number. But it isn't what you expect. There are lists of Unicode characters here, or in a format easier to read, here: try "basic Latin" first.

Now a char is an unsigned integer number between 0 and 65535 (ffff), but expressed as one of the Unicode characters in the charts you have just seen. You can cast it to an int, or you can cast an int to a char. If your int is 1234, your char will be 1234. If your int is outwith the range 0 to 65535, you will have to try out an app to see what value it casts to. You can look up on the acme website I quoted what 1234 means. It is "SEE" in Ethiopian if you use hex numbering.

If a char is a number you can add subtract multiply and divide it.

Try the following. Subtract two char values and print out what you get.
Find the methods about numeric value in the Character class and try them with different inputs.
 
Justin Fox
Ranch Hand
Posts: 802
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
when i meant convert, i mean't cast...

like...

double a = 2.0;

int b = (int)a;

but with a char instead of a double...

sorry, didn't mean to throw you off...

the reason is, in the dll we have to store each individual integer of

the LongInt as a char in each node...

i'm just stuck on how to do the input like so



the reason it's confusing, is that...

say i scan the a with scan.nextLine() and store in it a variable answer.

like so



can i do the following? :

LongInt answer = new LongInt();

would that be legit?

because i think it would just create a variable name answer holding a

reference to a LongInt object...

or is their a .getValue() method i could use to initiate the value of

the answer variable so that, in fact, i have a variable 'a' that holds the

reference to LongInt...

thx,

Justin

sorry if its confusing...
 
Campbell Ritchie
Marshal
Posts: 56536
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can i do the following? :

LongInt answer = new LongInt();

would that be legit?
Yes. But it all depends what you have in your LongInt constructor.
i was going to use an LongInt[] to store them all then just sift through
when i go to mult/add.
If you have an array in your LongInt class you can iterate through the individual characters of the String and convert them to numbers and put them into your array.

BTW: It is a good idea to iterate through the String before you do that and throw a NumberFormatException if any of the chars doesn't fall within the range '0' to '9'.
 
Peter Chase
Ranch Hand
Posts: 1970
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Justin Fox:
the long ints have to be created with DLL's.


I guess you are using "DLL" as an abbreviation for "Doubly-Linked List". Please be advised that many developers (particularly those using Windows) would not interpret it that way.

In the world of Windows, "DLL" means "Dynamic Link Library". So I thought you were talking about interfacing your Java code to some native Windows code using a DLL. It took me a while to realise it wasn't about that.
 
Justin Fox
Ranch Hand
Posts: 802
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sorry, about the DLL thing, and yes, I was speaking of doubly linked lists..

but i've learned that we do not have to make it "interactive", throught the "command prompt".

so here is my new(er) code....



ok, now what i want to do is:

f = a + b;

now to do this, i will have to have a .plus(LongInt num) method..

but in the following code, if written in the same file, will the this work properly?



because i want to pick up the last node in each one that is being added.

and then pick up the character value in that node, convert it to int, then

add them.

then call .prev for both again and continue...

but would this.prev automatically call head.prev?


thanks for the help!
Justin
 
Campbell Ritchie
Marshal
Posts: 56536
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don't know. I worked out how you could do it this morning with arrays. And I didn't understand what you meant by DLL; I couldn't understand what a dynamically linked library had to do with it.

Do you have any method of reaching a particular node in your linked list?
Can you tell it to get(0), get(1), get(2), etc?
Do you have any set() methods for a particular node?
Can you work out node(0).setValue(node(0) + otherList.node(0)); ?
If (node(0) > 9), can you set node(0) = node(0) % 10; and node(1) = node(1) + 1; ?

Can you understand a word of this?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!