定义一个单链表节点结构: struct node{ int data; struct node *next }; struct node *p,*q;

2025-05-23 07:17:40
推荐回答(3个)
回答1:

typedef struct node{
int data;
struct node *next;
}Lnode,*List;

void insert(List p,List q){
if(p == NULL)exit(0);
else
{
q->next = p->next;
p->next = q;
}
}

根据楼主的意思,写了这个这个函数,不过感觉那个参数列表不是很对的样子,因为缺个表头,但你又没说- -

回答2:

你的操作有疑问,q插到p后,那q前面的结点呢,p后面的呢,
如果q是第一个,p是最后一个,那就没问题,直接:p->next=q

回答3:

node * tmp1 = p->next;
p->next = q;
q->next = tmp1;