我无聊....来个全的....
/*****************************************************************
** HighlightCodeV3.0 software by yzfy(雨中飞燕) http:// **
*****************************************************************/
typedef struct node{
int data;
node* next;
} node_m,*pnode_m;
pnode_m creatlist(pnode_m list,int size)
{
printf("please input the value of node: \n");
pnode_m tnode;
int value;
while(size>0)
{
scanf("%d",&value);
tnode = (pnode_m)malloc(sizeof(node_m));
tnode->next = NULL; tnode->data = value;
if(list==NULL) list = tnode;
else
{
tnode->next = list;
list = tnode;
}
--size;
}
return list;
}
void freelist(pnode_m list)
{
pnode_m pnode = list;
while(pnode!=NULL)
{
list = pnode->next;
free(pnode);
pnode = list;
}
}
pnode_m insertNode(pnode_m list,pnode_m node,const int cp)
{
pnode_m check = list,precheck=NULL;
int i=1;
for(;i<cp;++i) {precheck=check;check=check->next;}
if(precheck==NULL) {node->next=check;list=node;}
else
{
node->next = check;
precheck->next = node;
}
return list;
}
pnode_m deleteNode(pnode_m list,const int cp)
{
pnode_m check = list,precheck=NULL;
int i=1;
for(;i<cp;++i) { precheck=check;check=check->next;}
if(precheck==NULL) list=check->next;
else precheck->next = check->next;
free(check);
return list;
}
pnode_m exchangeNode(pnode_m list)
{
if(list==NULL) return NULL;
else
{
pnode_m precheck=NULL,check=list,checksuc=list->next;
for(;checksuc!=NULL; )
{
check->next=checksuc->next;
checksuc->next=check;
if(precheck!=NULL) precheck->next=checksuc;
else list=checksuc;
precheck=check;
check=check->next;
checksuc=(check==NULL?NULL:check->next);
}
return list;
}
}
void printlist(pnode_m list)
{
while(list!=NULL)
{
printf("%d->",list->data);
list=list->next;
}
putchar('\n');
}