gpt4 book ai didi

java - 使用双向链接列表按优先级排序

转载 作者:行者123 更新时间:2023-12-01 19:19:56 25 4
gpt4 key购买 nike

我被困在这里,任何人都可以帮助我解决这个问题。

                Integer Personid = rs.getInt("Personid");
String FirstName = rs.getString("FirstName");
String LastName = rs.getString("LastName");
String DateOfArrival = rs.getString("DateOfArrival");
String PassportNumber = rs.getString("PassportNumber");
String PriorityLevel = rs.getString("PriorityLevel");
PriorityNumber = rs.getString("PriorityNumber");

ArrayList<String> queue = new ArrayList<String>();

queue.add(Personid.toString());
queue.add(FirstName);
queue.add(LastName);
queue.add(DateOfArrival);
queue.add(PassportNumber);
queue.add(PriorityLevel);
queue.add(PriorityNumber);

System.out.println(queue);


结果:

 [218, Akhil, Chandran, 2020-02-21, KH1234567, High Priority, 3]
[219, Emma, Sony, 2020-11-11, HJ73737377, Low Priority, 1]
[220, Michele, Philip, 2021-10-22, HJ989898, Medium Priority, 2]
[221, Zania, Zing, 2024-09-26, GH565656, Medium Priority, 2]
[222, Pole, Mathew, 2020-04-14, HY212121, High Priority, 3]
[223, Myra, Mary, 2020-03-04, GH6666666, High Priority, 3]


需要获得:

  [218, Akhil, Chandran, 2020-02-21, KH1234567, High Priority, 3]
[222, Pole, Mathew, 2020-04-14, HY212121, High Priority, 3]
[223, Myra, Mary, 2020-03-04, GH6666666, High Priority, 3]
[220, Michele, Philip, 2021-10-22, HJ989898, Medium Priority, 2]
[221, Zania, Zing, 2024-09-26, GH565656, Medium Priority, 2]
[219, Emma, Sony, 2020-11-11, HJ73737377, Low Priority, 1]

最佳答案

假设您的代码段在“ rs”上循环运行,那么您的输出将保持不变。

您可以定义另一个数据结构,它可以容纳数组列表,并使用排序算法“插入排序”将每个迭代的当前“队列”添加到先前定义的数据结构中。输出数据结构将为您提供所需的排序版本。

如果需要按多个字段排序,请使用“基数排序”。

当然,这只是一个概念,实现就在您手中。

希望这可以帮助。

关于java - 使用双向链接列表按优先级排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59369639/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com