我的问题是,我有两个列表,为了简单起见,有4-4项,这些不是唯一的项目。按计算值排序的项目,我们称其为秩。现在我必须显示每页两个项目从8个项目,但只有唯一的价值排序。
所以我有两份清单:
列表A
A - 1
B - 2
D - 5
C - 6
列表B
A - 2
D - 3
B - 4
C - 5
因此,我需要以偏移量为0的限制2排序的项目的第一页,这将是:
首页
A(list A) - 1
B(list A) - 2 // we skip the A from list B because we need unique values
因此,第二页预计如下:
预期第2页
D(list B) - 3
C(list B) - 5
但是,由于偏移量(跳过每个列表中的前两项),实际的第二页将导致:
实际第2页
B(list B) - 4
D(list A) - 5 // or C - 5 from list B
值将被复制(B),这显然是不好的。
现在我能想到的唯一解决方案是把所有的列表合并成一个有序的列表并在这个列表上应用分页,但是这是我做不到的事情。我通过一个API访问这些列表,即使它是一个内部API,我不得不把它看作是一个第三方API,不能更改。API只接受排序方向(asc、desc)、偏移量和限制参数。
我应该实时显示这些值,如果列表中有变化,我必须显示这些更改。
有什么建议吗?
发布于 2014-07-04 03:23:48
我有一个主意。请复习一下。
假设:两个列表都有相同的条目。
下面是解决问题的示例代码:
node * H_A = List_A.head
node * H_B = List_B.head
while ((H_A == NULL) || (H_B == NULL))
{
// Here I am maintaining an invariant that value pointed by H_B is
// greater than the value pointed by H_A.
if (H_B > H_A)
{
swap (H_B, H_A);
}
Display value of H_A on the current page. This is the first value of the page.
Move H_A to next value.
if (value.H_B > value.H_A)
{
Display value of H_A on the current page. This is the second value of the page.
}
else
{
Display value of H_B on the current page. This is the second value of the page.
}
Move H_A to next value.
Move H_B by two values.
Move to next page. This page is completed.
}
如果它不能解决你的问题,请告诉我。我们会努力做到这一点的。
https://stackoverflow.com/questions/24513007
复制相似问题