题目:已知某一无头单链表的某一结点p(不是第一个,也不是最后一个),向该结点之前插入已知结点q。
//*****************************************
//题目:已知一个不知道头结点的单链表的某一个
// 结点(不是头结点也不是最后一个结点),
// 怎样在此结点之前插入一个新结点?
//*****************************************
//#include <stdio.h>
typedef struct Lnode
{
int data;
struct Lnode *next;
}Lnode;
void swap(int *p,int *q)
{
int *tmp;
tmp = NULL;
tmp = p;
p = q;
q = tmp;
}
//A->pcur->B->C.....
//A->pcur->new->B->C.....
//A->new->pcur->B->C.....
int insertnode(Lnode *pcur,Lnode *new)
{
if(NULL == pcur)
{
printf("input error!\n");
return -1;
}
new->next = pcur->next;
pcur->next = new;
swap(&pcur->data,&new->data);
return 0;
}