| |

VerySource

 Forgot password?
 Register
Search
View: 1752|Reply: 10

How to sort two rows of data?

[Copy link]

3

Threads

17

Posts

15.00

Credits

Newbie

Rank: 1

Credits
15.00

 China

Post time: 2020-1-11 07:40:01
| Show all posts |Read mode
such as:
There is such a set of data
               Character integer
               Computer a
               Accessory b
               Memory c
               Main box d
               Graphics card f
Now you have sorted the data of integer variables from large to small by using the sorting method, but how can you also arrange the character types according to the integer variables from large to small?
Such as:
    first:...
    second:...
    .
    .

Or what method is best?
Reply

Use magic Report

0

Threads

60

Posts

23.00

Credits

Newbie

Rank: 1

Credits
23.00

 China

Post time: 2020-1-14 19:00:02
| Show all posts
How to also arrange the character type according to the integer variable from large to small?

I do not understand the meaning
Reply

Use magic Report

3

Threads

17

Posts

15.00

Credits

Newbie

Rank: 1

Credits
15.00

 China

 Author| Post time: 2020-1-15 13:36:02
| Show all posts
I mean:
How to arrange this set of data from big to small
               Character integer
               Computer a
               Accessory b
               Memory c
               Main box d
               Graphics card f
The final result can be displayed like this:
first:....
second:....
.
.
.
Note: a, b, c, d ... on the right are all variables.
Reply

Use magic Report

0

Threads

60

Posts

23.00

Credits

Newbie

Rank: 1

Credits
23.00

 China

Post time: 2020-1-15 15:36:01
| Show all posts
In a table, of course, you can sort by integer variables.
Reply

Use magic Report

0

Threads

58

Posts

32.00

Credits

Newbie

Rank: 1

Credits
32.00

 China

Post time: 2020-1-15 15:45:02
| Show all posts
int a [] = {...}

HashTable strHT = new HashTable ()
strHT.add ("a", "Computer")
strHT.add ("b", "Accessory")
...

a sorted,
foreach (int i in a) {
   strHT.Items (i.ToString ())
}
Reply

Use magic Report

2

Threads

9

Posts

7.00

Credits

Newbie

Rank: 1

Credits
7.00

 China

Post time: 2020-1-15 16:45:01
| Show all posts
Haha
Reply

Use magic Report

3

Threads

17

Posts

15.00

Credits

Newbie

Rank: 1

Credits
15.00

 China

 Author| Post time: 2020-1-16 19:09:01
| Show all posts
int a [] = {...}

HashTable strHT = new HashTable ()
strHT.add ("a", "Computer")
strHT.add ("b", "Accessory")
...

a sorted,
foreach (int i in a) {
   strHT.Items (i.ToString ())
}
...............................

Still not working, strHT.Items (i.ToString ()) went wrong
Reply

Use magic Report

3

Threads

17

Posts

15.00

Credits

Newbie

Rank: 1

Credits
15.00

 China

 Author| Post time: 2020-1-20 11:09:01
| Show all posts
Hey, does anyone know how to solve this problem?
Reply

Use magic Report

0

Threads

322

Posts

115.00

Credits

Newbie

Rank: 1

Credits
115.00

 China

Post time: 2020-1-20 18:18:02
| Show all posts
Hashtable ht = new Hashtable ();
ht.Add ("2", "Computer");
ht.Add ("1", "Accessory");
ht.Add ("9", "Memory module");
ht.Add ("0", "Chassis");
ht.Add ("7", "Graphics card");
ht.Add ("3", "Sound Card");
Ranch
System.Collections.ArrayList al = new ArrayList (ht);
al.Sort (new A ());
object [] o = al.ToArray ();
Ranch
for (int i = 0; i <o.Length; i ++)
{
DictionaryEntry de = (DictionaryEntry) o [i];
Response.Write (de.Key + ":" + de.Value + "<BR>");
}







class A: IComparer
{
#region IComparer members

public int Compare (object x, object y)
{
// TODO: add A.Compare implementation
DictionaryEntry d1 = (DictionaryEntry) x;
DictionaryEntry d2 = (DictionaryEntry) y;
Ranch
return Convert.ToInt32 (d1.Key)-Convert.ToInt32 (d2.Key);
}

#endregion

}
Reply

Use magic Report

0

Threads

322

Posts

115.00

Credits

Newbie

Rank: 1

Credits
115.00

 China

Post time: 2020-1-20 18:36:01
| Show all posts
Of course, it will be simpler if you add data to the DataTable.

DataView.Sort = "Field" is fine
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list