-
Heada and headb are both singly linked lists with leading nodes. In this algorithm, we delete the common elements from the ith element in the heada linked list, and then insert the single-linked list heada before the jth element of the headb.
if ( i < 1 ||len < 1 ||j < 1)
printf ( "The parameter is incorrect");
exit ( 0);
p = heada;p is the working pointer of the linked list a, which is initialized as the header pointer of a, and when the ith element is found, p points to the i-1 element.
int k = 0;Count.
while ( p != null &&&k < i-1).
k++;p = p->next;
If ( p == null) i is too large, exit the algorithm.
printf ( "The %d given is too big", i);
exit ( 0);
q = p->next;q is the working pointer, which initially points to the first node of the A linked list.
k = 0;
while ( q != null &&k < len)
k++;u = q;
q = q->next;
free ( u);Delete the node and move the pointer back.
if ( k < len)
printf ( "The %d given is too big", len);
exit ( 0);
p->next=q;A linked list removes len elements.
if ( heada->next!=null) heada->next=null indicates that all nodes in the linked list have been deleted and do not need to be inserted into table b.
while ( p->next != null) to find the tail node of a.
p = p->next;
q = headb;q is the working pointer of linked list B.
k = 0;Count.
while ( q != null &&k < j - 1) Find the jth node, and when the search is successful, q points to the j-1 node.
k++;q = q->next;
if ( q == null)
printf ( "The %d given is too big", j);
exit ( 0);
p->next = q->next;Chaining the a-linked list in.
q->next = heada->next;The first element node chain of A follows the J-1 node of B.
free ( heada);Release the A header node.
return headb;
-
Because I don't know the specific problem, I can only write the algorithm idea to provide reference, assuming that the node type of the singly linked list is nodenode *p, *q, *a; p=;(the first element of a) int k; for(k=0;k
-
Look at Yan Weimin's data structure.
Look"Malloc", there is an article on the first page that is clearly written.
Scope. You static char *chh;
static char *ch1;Although the address pointed to by the two pointers does not change, have you ever wondered whether the memory address they point to has been released, char chc[10]; It's local, the function is out, the lifecycle is over, and you're trying to access it with a pointer in void times(). >>>More
Use the ITOA function.
Prototype: extern char *itoa(int i); >>>More
I wrote it myself and solved it directly with a one-dimensional array. >>>More