• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Doubt regarding natural ordering Example

 
Ranch Hand
Posts: 1164
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all

Please have a look at the code below:



The output I got is : > f< >FF< >f < >ff<
Please explain how.

Regards
Mansukhdeep Singh
 
Ranch Hand
Posts: 633
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What is this?
 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Write down each of those Strings, then the numeric values of their respective characters (I think you can confine your attentions to the second character if they all start with >, except for "f " and "ff" where you look at the 3rd character too). If you have difficulty working out the numeric values, refer to this Unicode page.

Google for ASCIIbetical order.

By the way: because you used System.out.print rather than System.out.println, your output is very difficult to understand.
 
Mansukhdeep Thind
Ranch Hand
Posts: 1164
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:Write down each of those Strings, then the numeric values of their respective characters (I think you can confine your attentions to the second character if they all start with >, except for "f " and "ff" where you look at the 3rd character too). If you have difficulty working out the numeric values, refer to this Unicode page.

Google for ASCIIbetical order.

By the way: because you used System.out.print rather than System.out.println, your output is very difficult to understand.



Hi Sir
I put System.out.println(pq3.poll()); instead and got the output:
> f<
>FF<
>f <
>ff<
I guess they have used the angle brackets to show the padding of whitespace before or after the charachter.
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Mansukhdeep, when you use code tags, please write them with lower-case letters: [ code ] ... [ /code ]

You wrote them with a capital C: [ Code ] ... [ /Code ]

Due to a bug in the forum software (we're looking into it), this messes up some of the source code between the tags.
 
Ranch Hand
Posts: 1051
Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
angle brackets are used to show the padding of spaces here........

so you can sort the elements using natural order.........

which
1.white space....
2.capital later
3.small letter


hence the output
 
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Jesper Young wrote:Due to a bug in the forum software (we're looking into it), this messes up some of the source code between the tags.


It's not a bug, it's a feature!
 
Campbell Ritchie
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The <> brackets are part of the Strings. They are printing in ordinary ASCIIbetical order, as I hinted earlier.
 
Campbell Ritchie
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

shanky sohar wrote: . . . natural order.........

which
1.white space....
2.capital later
3.small letter
. . .

That is a gross over-simplification. Did you look at the Unicode link I quoted earlier?
 
Mansukhdeep Thind
Ranch Hand
Posts: 1164
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:The <> brackets are part of the Strings. They are printing in ordinary ASCIIbetical order, as I hinted earlier.



That is fine sir. I had a look at the Unicode standard pdf according to which:

SP (space) is 0020
< (less than) is 003C
> (greater than) is 003E
f (small f) is 0066
F (capital F) is 0046

So, the order goes like 'White space' comes before 'F' comes before 'f' comes before '<' comes before '>'

Hence, < should come before >. But in the output it is the opposite(> f<). How come?
 
Ranch Hand
Posts: 1179
Mac OS X Eclipse IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Where in the output should < come before > ??

Each element in the array start with a > and end with a < - it is what is been placed between them you need to look at.
 
Mansukhdeep Thind
Ranch Hand
Posts: 1164
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Rene Larsen wrote:Where in the output should < come before > ??

Each element in the array start with a > and end with a < - it is what is been placed between them you need to look at.



Hi Rene
So you mean to say that the angle brackets are not a part of the String elements? But Campbell said the opposite. Please clarify whether the angles are a part of the string elements while prioritizing or not.

Regards
Mansukhdeep
 
Rene Larsen
Ranch Hand
Posts: 1179
Mac OS X Eclipse IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Mansukhdeep Thind wrote:

Rene Larsen wrote:Where in the output should < come before > ??

Each element in the array start with a > and end with a < - it is what is been placed between them you need to look at.



Hi Rene
So you mean to say that the angle brackets are not a part of the String elements? But Campbell said the opposite. Please clarify whether the angles are a part of the string elements while prioritizing or not.

Regards
Mansukhdeep


They are part of the String element - but the sorting will not be performed on the angle brackets, because they are the same in all elements.
 
Campbell Ritchie
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Mansukhdeep Thind wrote: . . . 'White space' comes before 'F' . . .

Not "whitespace" but the "space" character. There are other whitespace characters which come after F.

Hence, < should come before >. But in the output it is the opposite(> f<). How come?

Rene Larsen has given you the answer to this twice. Each string starts with > and ends with < so you always get >: before <. As you say, they are the same in all elements.
 
Mansukhdeep Thind
Ranch Hand
Posts: 1164
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:

Mansukhdeep Thind wrote: . . . 'White space' comes before 'F' . . .

Not "whitespace" but the "space" character. There are other whitespace characters which come after F.

Hence, < should come before >. But in the output it is the opposite(> f<). How come?

Rene Larsen has given you the answer to this twice. Each string starts with > and ends with < so you always get >: before <. As you say, they are the same in all elements.



Aye aye sir. Thanks a pile Sheriff Campbell and Monsieur Rene.
 
Campbell Ritchie
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You're welcome
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic