c - Sequential searching with sorted linked lists -


  structure record_net * sequential_search (structure record_ode * list, full target) {struct Record_node * cur; Cur = List-> Head; If (CR == faucet = cur-> KEY> gt; = target) {return tap; } While (tax-> next! = Null) {if (cur-> gt; next-> key> = target) {return; } Cur = cur- & gt; next; } Return; }  

I can not explain this pseudo-angle Can anyone tell me how this program works and flows? Looking at this pseudocode, search for the value in a link list and a list that is in ascending order, what will the program return?

a. The biggest value in the list is less than the target - b the largest value in that list is less than or equal to the target - the smallest value in the list is greater than or equal to the target - d. Goal - The smallest value in the e list

and the list is [1, 2, 4, 5, 9, 20, 20, 24, 44, 69, 70, 71, 74, 77, 92 ] And goal 15, how much did it compare? (Here, compare the value of the comparison goal)

EDIT: @Stephen I'm sorry if I have been harassing my question is asking

OK, because I Visual Basic is used for programming, I consider 'CR-> key' in line 4 of the program because the 'Q' key is the same or similar, but '+ =' means' pre-value and the latter value Is equal to the later value ', in the form of' -> ' I can interpret the same way. '+ =' This part I am facing problems.

I am experiencing another problem, use Pointers in the Record_node (if it is an indicator). I'm not even sure if I know what I do not know! I understand this program as a recursive algorithm.

itemprop = "text">

Well, because I'm using programming in Visual Basic, in the line 4 of the program, CR-> key 'because the' Q 'key is bigger than or equal to the key, but' + = 'means' pre-value plus'' value is equal to later value ', I can explain - '' Similarly '+ =' This part is one of the problems that I am facing I

That's the problem, I'm glad you made it clear that :)

this code is c (or c ++ ). The language dereference points for -> and indicates members of a structure. IIRC, VB does not have pointers, so you will call struct.member or cur.next .

  while (cur-> Next! = Null) {// The next node of the current is not zero. }  

NULL is being used to mark the end of the list.

cur-> next-> gt; ; The key means "key of the node after the current one" If you attract a linked list with ascending values ​​and find out the program, it can help you to visualize it.

While at some point during the execution of the loop, you will have:

  + - + + - + + - + | 2 | - | 4 | - | 7 | --Non + - + + + - + ^ ^ ^ | | |  

BTW, real is greater or equal operator & gt; = .

BTW2, it is not recursive, it will be a recursive function that calls itself (you can execute it repeatedly) This function is repeated (this uses a loop) A recursive An example of algorithm is:

  node * sequential_search (list * list, int target) {if (list!) Return tap; If (target == list-> key) return list; Return Sequential Search (List-> Next, Goal); }  

Hope that helps!


Comments