asort with two numbers & 3 Numbers

asort with two numbers & 3 Numbers

Postby Silvio.Falconi » Wed Oct 26, 2022 9:29 am

ASort( aData, nil, nil, { |x| IF (x[1]<x[2], x[ 1 ] > x[ 2 ],x[ 2 ] > x[ 1 ]) } )

I'm afraid this ordering is wrong how can i fix it?
that is, now the result obtained is this
Code: Select all  Expand view

A   B
1   11
2   12
3   13
4   14
5   15
6   16
7   17
8   18
9   19
10  20
21  11
22  12
23  13
24  14
25  15
26  16
27  17
28  18
29  19
30  20
31  21
32  22
33  23
34  24
35  25
36  26
37  27
38  28
39  29
40  30
41  31
42  32
43  33
44  34
45  35
46  36
47  37
48  38
49  39
50  40
51  41
52  42
53  43
54  44
55  45
56  46
57  47
58  48
59  49
60  50
61  51
62  52
63  53
64  54
65  55
66  56
67  57
68  58
69  59
70  60
71  61
72  62
73  63
74  64
75  65
76  66
77  67
78  68
79  69
80  70
81  1
82  2
83  3
84  4
85  5
86  6
87  7
88  8
89  9
90  10
   
 


instead I would like this

Code: Select all  Expand view

1   11
1   81
2   12
2   82
3   13
3   83
4   14
4   84
5   15
5   85
6   16
6   86
7   17
7   87
8   18
8   88
9   19
9   89
10  20
10  90
11  21
12  22
13  23
14  24
15  25
16  26
17  27
18  28
19  29
20  30
21  31
22  32
23  33
24  34
25  35
26  36
27  37
28  38
29  39
30  40
31  41
32  42
33  43
34  44
35  45
36  46
37  47
38  48
39  49
40  50
41  51
42  52
43  53
44  54
45  55
46  56
47  57
48  58
49  59
50  60
51  61
52  62
53  63
54  64
55  65
56  66
57  67
58  68
59  69
60  70
61  71
62  72
63  73
64  74
65  75
66  76
67  77
68  78
69  79
70  80
71  81
72  82
73  83
74  84
75  85
76  86
77  87
78  88
79  89
80  90
 


that is in practice the sorting is from the number 1 and even if the number 1 is in the second column but it is at the bottom it is inserted before the 2 and so on ...


Perhaps it is more clear here

I have :

1 2
3 2
4 3
5 4
6 5
7 6
8 7
9 8
10 9

but I wish it was

1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 9
9 10

this does it to me right but on the contrary that is it starts from number 90
ASort( aData, nil, nil, { |x|IF(x[2]>x[1], x[ 2 ] > x[ 1 ],x[ 1 ] > x[ 2 ]) } )
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
User avatar
Silvio.Falconi
 
Posts: 7052
Joined: Thu Oct 18, 2012 7:17 pm

Re: asort with two numbers & 3 Numbers

Postby nageswaragunupudi » Wed Oct 26, 2022 11:55 am

Code: Select all  Expand view

If( x[ 1 ] == y[ 1 ], x[ 2 ] < y[ 2 ], x[ 1 ] < y[ 1 ] )
 
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10625
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: asort with two numbers & 3 Numbers

Postby Silvio.Falconi » Thu Oct 27, 2022 10:24 am

nageswaragunupudi wrote:
Code: Select all  Expand view

If( x[ 1 ] == y[ 1 ], x[ 2 ] < y[ 2 ], x[ 1 ] < y[ 1 ] )
 


Nages,
a sample I have this
Image

how I can have as
this ?

1 2
1 90
2 3
3 4
4 5
5 6
6 7
7 8
8 9
9 10
10 11

the test to try
Code: Select all  Expand view
#include "fivewin.ch"
Function test()
local n,k,h
local ntotale
local nValore:=1
local aTmp :={}

For n= 1 to 90
        For k= 1 to 90
              nTotale  := DistanceC(n,k)
              If  nTotale=nvalore
                    nAt := AScan( aTmp, { |a| a[1] = k .or. a[2] = n} )
                    If nAt == 0
                       aadd(aTmp,{n,k})
                    Endif
                  Endif
            next
         next

         //Repeated
         for h=1 to Len(atmp)
           If  atmp[h][1] == atmp[h][2]
               HB_ADel( aTmp, h, .t. )
            Endif
        next

 ASort( aTmp, nil, nil, { |x,y| If( x[ 1 ] == y[ 1 ], x[ 2 ] < y[ 2 ], x[ 1 ] < y[ 1 ] ) } ) //nages

 xbrowser aTmp  TITLE ltrim(str(len(aTmp)))

retu nil

Function DistanceC(n1,n2)
   local nNum:=0
   local nTemp:=0
           IF n1>n2
             nTemp:= n1-n2
          elseif n1<n2
             nTemp:= n2-n1
          Endif
          If nTemp > 45          
             nTemp:= 90-nTemp
          Endif
 nNum := ntemp
     return nNum

 
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
User avatar
Silvio.Falconi
 
Posts: 7052
Joined: Thu Oct 18, 2012 7:17 pm


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 99 guests