Title : Design of a recursive algorithm, a value x to remove all nodes do not lead to a single node in the linked list L.
Keywords : + recursive algorithm does not take the lead in a single list node + Delete by value
Ideas
concern: recursive algorithm design focus is to find the "recursive" part, a function that is called repeatedly to change the part of the relevant variables
Set F (L, x) is a function of: L led to delete a single linked list node pointer nodes is equal to all values of x, clearly f (L-> next, x)
1. Retrograde generic function: + traversal cycle interchangeable head and tail elements
required variables: L, relative to the beginning and end node index: from, to
reverse the subscript node set off: <(to-from + 1 ) / 2
Table 2. Retrograde entire
tag is required: 0, n-1
3. The first p element of the first stage; the second section element is left to rest
two are Retrograde: 0, p; p + 1 , n-1
void Reverse(int R[],int from,int to){
int i,temp;
for(i=0;i<(to-from+1)/2;i++){
temp=R[from+i];
R[from+i]=R[to-i];
R[to-i]=temp;
}
void Converse(int R[],int n,int p){
Reverse(R,0,n-1)
Reverse(R,0,n-p-1)
Reverse(R,n-p,n-1)}
}