int JumpSearchWithCategory(Node *head, string keywork)
{
int n = length(head);
int step = sqrt(n);
int prev = 0;
int m = min(step,n)-1;
Node *nMin = getNodeAt(head, min(step,n)-1);
Node *nPrev = getNodeAt(head, prev);
while(nMin->book.theloai < keywork){
prev = step;
step += sqrt(n);
if(prev >= n)
return -1;
}
while (nPrev->book.theloai < keywork)
{
prev++;
if(prev == min(step, n))
return -1;
}
if(nPrev->book.theloai == keywork)
return prev;
return -1;
}
With this code, I can only find the first guy in the list. Before searching, I sorted the list in order but only found the first guy.
I tried many different ways but it didn’t work, so I came here to ask for help
New contributor
Nguyễn Minh Nhật is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.