Home > Back-end >  A linear table, genuflect is begged (a1, a2,... , an) (n> 3) by leading the singly linked list of
A linear table, genuflect is begged (a1, a2,... , an) (n> 3) by leading the singly linked list of

Time:09-18

A linear list (a1, a2,... , an) (n> 3) by leading the singly linked list of nodes storing L, design an efficient algorithm for the location of the elements (that is, the number of elements) [n/2]

CodePudding user response:

A pmid two Pointers, a pend pmid walk the one step at a time, take two steps pend until pend on the end, the pmid is the middle position,
Seem to be effective, the best in the length of the head nodes stored in a single table,

CodePudding user response:

 
ElemType Midnode (LinkNode * L)
P={LinkNode * L - & gt; Next, * q=p;
While (p - & gt; Next!=NULL & amp; & P - & gt; Next - & gt; Next!=NULL)
{p=p - & gt; Next - & gt; Next;
Q=q - & gt; Next;
}
Return the q - & gt; The data;