Re: Sorting an Edge List
- From: "Anthony D'Agostino" <gamma-ray@xxxxxxxxxxxxxxxx>
- Date: Fri, 29 Apr 2005 23:37:39 -0400
I found my old bubble sort solution:
============================================
def esort(edges):
while 1:
swaps = 0
for j in range(len(edges)-2):
if edges[j][1] != edges[j+1][0]:
edges[j+1],edges[j+2] = edges[j+2],edges[j+1] # swap
swaps = 1
if swaps == 0: break
return edges
print esort([('A','Y'), ('J','A'), ('Y','J')])
print esort([(5,0), (6, -12), (0,6), (-12, 3)])
============================================
The list can be any length and there will always be multiple valid
solutions, depending on which edge you start with. I'm using this to sort
edges for mesh subdivision. I just thought there might be a more elegant way
to write it.
.
- Follow-Ups:
- Re: Sorting an Edge List
- From: Bengt Richter
- Re: Sorting an Edge List
- References:
- Sorting an Edge List
- From: Anthony D'Agostino
- Re: Sorting an Edge List
- From: Roy Smith
- Sorting an Edge List
- Prev by Date: Re: Python Challenge ahead [NEW] for riddle lovers
- Next by Date: Re: Killing process
- Previous by thread: Re: Sorting an Edge List
- Next by thread: Re: Sorting an Edge List
- Index(es):