Win a copy of The Journey To Enterprise Agility this week in the Agile and Other Processes forum! And see the welcome thread for 20% off.
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

How to sort these lines?  RSS feed

 
Ranch Hand
Posts: 514
1
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello!

I really need a help on solving one problem.
I have many lines and I need the way to sort them by specified order. The lines are on picture.

I need them to be sorted in this order:
0 5 1 -- 0 is horizontal start and 5 is horizotal end, 1 is vertical position called height.
0 4 2 -- again 0 is horizontal start, 4 is horizontal end and 2 is vertical position(height)
1 4 3
2 3 4
0 5.5 5
6 7 5
6.0 6.2 2
6.2 6.4 3
6.4 6.6 4
6.6 6.8 3
6.8 7.0 2
9.5 15.5 3
10 12.5 2
12.5 15 2
10 15 1
16 17 5
16.0 16.1 2
16.2 16.3 3
16.4 16.5 4
16.6 16.7 3
16.8 16.9 2
0 18 6
Each line of 3 numbers represent one line on picture. The first number is horizontal start of line and second is horizontal end and third number is vertical position
VisualPlatforms.PNG
[Thumbnail for VisualPlatforms.PNG]
 
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What are the sorting rules you wish to apply?
 
Bin Smith
Ranch Hand
Posts: 514
1
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Collection should be sorted from topmost line to bottommost as provided in my topic .

The top line(0,5,1) is the first in sorted collection, the second line(0,4,2) is second in sorted collection. The third line - 1 4 3 is the third in sorted coll.
These three numbers represent coordinates of line on picture:
0 is horizontal start of line
4 is horizontal end of line
1 is vertical position of line.
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To build the logic, you need to take a step back, forget all the existing data (lines) and formulate the sorting rules in simple english.
e.g.
If the x co-ordinate is the same for given two lines, the line with the higher y coordinate takes precedence over the other line
 
Bin Smith
Ranch Hand
Posts: 514
1
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Indeed. You are right.
I understood.

After some time I'll show you my java code for this.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!