sorting numbers in java

sorting numbers using logical OR operator

Page 1 of 1

8 Replies - 2450 Views - Last Post: 30 December 2009 - 08:14 PM Rate Topic: -----

#1 suryak  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 30-December 09

sorting numbers in java

Posted 30 December 2009 - 12:29 AM

hai!
How to sort numbers in java using logical OR operator?? :blink:
Is This A Good Question/Topic? 0
  • +

Replies To: sorting numbers in java

#2 alpha02  Icon User is offline

  • Sexy DIC God
  • member icon

Reputation: 47
  • View blog
  • Posts: 803
  • Joined: 20-May 06

Re: sorting numbers in java

Posted 30 December 2009 - 12:32 AM

Do you have more details on the assignment/task to do? We can't just provide help without some effort from you. Provide details and we will be happy to help you!

BTW, welcome to DIC! I suggest you post in the "Introduce yourself" forum in order for the members to greet you :)
Was This Post Helpful? 0
  • +
  • -

#3 janotte  Icon User is offline

  • code > sword
  • member icon

Reputation: 990
  • View blog
  • Posts: 5,141
  • Joined: 28-September 06

Re: sorting numbers in java

Posted 30 December 2009 - 01:11 AM

[rules][/rules]
Was This Post Helpful? 0
  • +
  • -

#4 sacstate2600  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 8
  • Joined: 20-December 09

Re: sorting numbers in java

Posted 30 December 2009 - 01:38 AM

wiki sorting algorithms
Was This Post Helpful? 0
  • +
  • -

#5 macosxnerd101  Icon User is offline

  • Self-Trained Economist
  • member icon




Reputation: 10486
  • View blog
  • Posts: 38,858
  • Joined: 27-December 08

Re: sorting numbers in java

Posted 30 December 2009 - 10:04 AM

View Postsacstate2600, on 30 Dec, 2009 - 04:38 AM, said:

wiki sorting algorithms


+1. Wikipedia is a very good resource for this type of thing.

@OP: Just FYI, most sorting algorithms don't use the logical or operator (at least none that I can think of). They instead sort elements based on their relation to other elements (comparison-swap sorts), which is a very common method that you'll find easy to implement. Some of these algorithms include Insertion Sort, Selection Sort, and Bubblesort. If you're up for a challenge, you may consider looking at Mergesort or Quicksort. Good luck! :)

(Also, just a note, we don't give out source code for requests like "Sorting routine using logical or operator." If you have a specific question, we are happy to help. Just remember, the more effort you show, the more helpful we can be.)
Was This Post Helpful? 0
  • +
  • -

#6 skaoth  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 91
  • View blog
  • Posts: 601
  • Joined: 07-November 07

Re: sorting numbers in java

Posted 30 December 2009 - 01:49 PM

The closest thing I can think up at the moment is radix sort.
The algorithm works by processing individual digits.
Was This Post Helpful? 0
  • +
  • -

#7 macosxnerd101  Icon User is offline

  • Self-Trained Economist
  • member icon




Reputation: 10486
  • View blog
  • Posts: 38,858
  • Joined: 27-December 08

Re: sorting numbers in java

Posted 30 December 2009 - 02:19 PM

View Postskaoth, on 30 Dec, 2009 - 04:49 PM, said:

The closest thing I can think up at the moment is radix sort.
The algorithm works by processing individual digits.


In all honesty, the OR operator doesn't work well in sorting algorithms because it leaves room for elements to fall out of place. Sorting algorithms should be very specific about the order for sorting. The only example I can think of where you might use the OR operator would be in the implementation of the Comparable interface (compareTo() method) for Objects. For example, if you are trying to sort elements in inventory by priority for ordering, you may need to specify which conditions take precedence; and sometimes, varying magnitudes of multiple attributes may toggle the priority. In these cases though, I prefer to use a quantitative system of some sort so that you have a method for comparison. Following the inventory example, this quantitative system would probably be the money earned in the given time period (usually the timeframe between orders).
Was This Post Helpful? 0
  • +
  • -

#8 skaoth  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 91
  • View blog
  • Posts: 601
  • Joined: 07-November 07

Re: sorting numbers in java

Posted 30 December 2009 - 02:32 PM

radix sort doesn't use the OR operator.
It is a very specific sort that is meant for integers. It is similar to bucket sort. It exploits the fact that integers can be 32 or 64 bits. Given this the algorithm attempts to provide faster than n lg n sorting.

I only make the reference to this because it is common to use bit shifting in the implementation, and potentially the confusion between bit shifting and logical OR.
Was This Post Helpful? 0
  • +
  • -

#9 macosxnerd101  Icon User is offline

  • Self-Trained Economist
  • member icon




Reputation: 10486
  • View blog
  • Posts: 38,858
  • Joined: 27-December 08

Re: sorting numbers in java

Posted 30 December 2009 - 08:14 PM

View Postskaoth, on 30 Dec, 2009 - 05:32 PM, said:

radix sort doesn't use the OR operator.
It is a very specific sort that is meant for integers. It is similar to bucket sort. It exploits the fact that integers can be 32 or 64 bits. Given this the algorithm attempts to provide faster than n lg n sorting.

I only make the reference to this because it is common to use bit shifting in the implementation, and potentially the confusion between bit shifting and logical OR.


Really, any person who doesn't understand the meaning of the word OR (as it is the exact same in the context of programming as well as in real life) shouldn't be working with sorting routines. They should probably be in kindergarten or the first grade instead. I also think that even if you didn't know what bit-shifting is, just by virtue of that it should be difficult to confuse it with the OR operator.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1