Asking inverse() function for List and ArrayList

  • Thread starter =?iso-8859-1?B?bW9vcJk=?=
  • Start date
?

=?iso-8859-1?B?bW9vcJk=?=

Hi,
I think to have a function to inverse a list is quite natural to be
embedded into the standard JSE library, how do you think about that?
 
I

IchBin

moop™ said:
Hi,
I think to have a function to inverse a list is quite natural to be
embedded into the standard JSE library, how do you think about that?
If I understand you question.. look at this link..

http://javaalmanac.com/egs/java.util/coll_SortList.html

--


Thanks in Advance...
IchBin, Pocono Lake, Pa, USA
http://weconsultants.servebeer.com/JHackerAppManager
__________________________________________________________________________

'If there is one, Knowledge is the "Fountain of Youth"'
-William E. Taylor, Regular Guy (1952-)
 
R

Roedy Green

inverse a list

what do you mean my that, sort a list in reverse order? make the first
last and the last first etc. Both of those are quite easy to do.
 
R

Rhino

moopT said:
Hi,
I think to have a function to inverse a list is quite natural to be
embedded into the standard JSE library, how do you think about that?
It depends on what you mean by inversing a list.

If you mean that a given list contains 0, 1, 2, 3, and 4 and you want the
inverse function to give you the other digits, i.e. 5 through 9 inclusive,
that might be reasonable, as long as you are willing to ignore that some
cultures have their own number systems that don't use the base 10 digits.

You'd have similar issues if you wanted to inverse letters. If a given list
contains 'A', 'B', and 'C' what inverse would you want to see? If you are an
English-speaker, you'd presumably want 'D' through 'Z' inclusive. But other
cultures that used other languages, alphabets, and scripts would want
something quite different.

At the very least, your inverse function would need to be very
culturally-sensitive if it was to work beyond the confines of English and
base 10 arithmetic.

Rhino
 
F

Francesco Devittori

Rhino said:
It depends on what you mean by inversing a list.

If you mean that a given list contains 0, 1, 2, 3, and 4 and you want the
inverse function to give you the other digits, i.e. 5 through 9 inclusive,
that might be reasonable, as long as you are willing to ignore that some
cultures have their own number systems that don't use the base 10 digits.

You'd have similar issues if you wanted to inverse letters. If a given list
contains 'A', 'B', and 'C' what inverse would you want to see? If you are an
English-speaker, you'd presumably want 'D' through 'Z' inclusive. But other
cultures that used other languages, alphabets, and scripts would want
something quite different.

At the very least, your inverse function would need to be very
culturally-sensitive if it was to work beyond the confines of English and
base 10 arithmetic.

Rhino

Given a list {0, 1, 2, 3, 4} I suppose the OP means a function that
returns {4, 3, 2, 1, 0}. Keep it simple :)

Francesco
 
R

Rhino

Francesco Devittori said:
Given a list {0, 1, 2, 3, 4} I suppose the OP means a function that
returns {4, 3, 2, 1, 0}. Keep it simple :)
You could be right but I think the key to the analysis of this problem is to
understand what the original poster meant by 'inverse', not just assume that
it was something simple. It's entirely possible that he/she _did_ want the
inverse of {0,1,2,3,4} to be {5,6,7,8,9} or maybe something else altogether,
not {4,3,2,1,0}. We can't know until we clarify what he/she meant. And until
you understand the question, you can't give a good answer.

Rhino
 
F

Francesco Devittori

Rhino said:
You could be right but I think the key to the analysis of this problem is to
understand what the original poster meant by 'inverse', not just assume that
it was something simple. It's entirely possible that he/she _did_ want the
inverse of {0,1,2,3,4} to be {5,6,7,8,9} or maybe something else altogether,
not {4,3,2,1,0}. We can't know until we clarify what he/she meant. And until
you understand the question, you can't give a good answer.

Rhino

You are right, but what you say is not the inverse of a list but the
inverse of each object in the list, which is something different.

list.inverse() vs. for(e: list) e.inverse();

(not even sure one could inverse an int anyway)

Francesco
 
I

IchBin

Francesco said:
You are right, but what you say is not the inverse of a list but the
inverse of each object in the list, which is something different.

list.inverse() vs. for(e: list) e.inverse();

(not even sure one could inverse an int anyway)

Francesco

Shame the OP does not return a comment to the intention.

--


Thanks in Advance...
IchBin, Pocono Lake, Pa, USA
http://weconsultants.servebeer.com/JHackerAppManager
__________________________________________________________________________

'If there is one, Knowledge is the "Fountain of Youth"'
-William E. Taylor, Regular Guy (1952-)
 
O

Oliver Wong

Francesco Devittori said:
You are right, but what you say is not the inverse of a list but the
inverse of each object in the list, which is something different.

list.inverse() vs. for(e: list) e.inverse();

(not even sure one could inverse an int anyway)

Francesco

When someone says the "inverse of an integer", they probably mean the
modular inverse. That means you need to have some sort of implied modulo m,
and the inverse (b^-1) of an integer b is such that b (b^-1) = 1 (mod m).

If m is not prime, then not every integer will have an inverse.

But for what it's worth, I had assumed the OP wanted the list returned
in reverse order, like Francesco initially did.

- Oliver
 
?

=?iso-8859-1?B?bW9vcJk=?=

I am so so so sorry for my innocent of Java Collections that I dont
know the existent of Collections.reverse(), exactly what IchBin replied
next to my post is the answer I am looking for. I dont know my ask for
help attracts your attentions so much, I am sorry for my confused
question. so I am very much thanks about all of you for your kindness
reactions, I feel so warm for your helps, thanks a lot!! Thanks!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top