/**************************
*1,2,3,4,5,6,8,9,10,11
*加入7
***************************/
#include<stdio.h>
#include<malloc.h>
#include<stdlib.h>
#define LEN 10
typedef struct node
{
int date;
struct node *next;
}*PNODE;
PNODE create_list(void);
bool charu_list(PNODE,int,int);
void transt_list(PNODE);
int main(void)
{
PNODE p;
p=create_list();
printf("All is:\n");
transt_list(p);
printf("\nAll is:\n");
charu_list(p,7,7);
transt_list(p);
printf("\n");
return 0;
}
PNODE create_list(void)
{
int i;
int a[]={
1,2,3,4,5,6,8,9,10,11
};
PNODE head=(PNODE)malloc(sizeof(node));
if(NULL==head)
{
printf("neicun feipei shibai!");
exit(-1);
}
PNODE tail=head;
tail->next=NULL;
for(i=0;i<LEN;i++)
{
PNODE pnew=(PNODE)malloc(sizeof(node));
if(NULL==pnew)
{
printf("neicun feipei shibai!");
exit(1);
}
pnew->date=a[i];
tail->next=pnew;
pnew->next=NULL;
tail=pnew;
}
return head;
}
bool charu_list(PNODE p,int pos,int value)
{
int i=0;
PNODE v=p;
while(NULL!=v && i<pos-1)
{
v=v->next;
++i;
}
if(i>pos-1 && NULL==v)
return false;
PNODE pnod=(PNODE)malloc(sizeof(node));
if(NULL==pnod)
{
printf("feipei neicun shibai!");
exit(-1);
}
pnod->date=value;
PNODE r=v->next;
v->next=pnod;
pnod->next=r;
return true;
}
void transt_list(PNODE head)
{
PNODE p=head->next;
while(NULL!=p)
{
printf("%d ",p->date);
p=p->next;
}
}