# include
# include
# define SIZE sizeof(struct student )
struct student
{
int data;
struct student * next;
};
struct student * creatlist()
{
struct student * head;
struct student * p1;
struct student * p2;
head = (struct student *)malloc(SIZE);
head->next = NULL;
p2 = head;
p1 = (struct student *)malloc(SIZE);
scanf("%d",&p1->data);
while(p1->data!=0)
{
p1->next = p2->next;
p2->next = p1;
p2 = p2->next;
p1 = (struct student *)malloc(SIZE);
scanf("%d",&p1->data);
}
p2->next = NULL;
free(p1);
return head;
}
struct student *creatlistjs(struct student * mhead)
{
struct student * head;
struct student * p1;
struct student * p2;
struct student * p3;
struct student * p4;
head =(struct student *)malloc(SIZE);
head->next = NULL;
p1 =(struct student *)malloc(SIZE);
p4 = head;
p3 = mhead;
p2 = mhead->next ;
while(p2!=NULL)
{
p1 = p3;
p1->next = p4->next ;
p4->next = p1;
p4 = p4->next ;
p3 = p3->next ;
p3 = p3->next ;
p2 = p2->next ;
p2 = p2->next ;
}
p4->next = NULL;
free(p1);
return head;
}
struct student * creatlistos(struct student *mhead)
{
struct student * head;
struct student * p1;
struct student * p2;
struct student * p3;
struct student * p4;
head =(struct student *)malloc(SIZE);
head->next = NULL;
p1 =(struct student *)malloc(SIZE);
p4 = head;
p3 = mhead;
p2 = mhead->next ;
while(p2!=NULL)
{
p1 = p2;
p1->next = p4->next ;
p4->next = p1;
p4 = p4->next ;
p3 = p3->next ;
p3 = p3->next ;
p2 = p2->next ;
p2 = p2->next ;
}
p4->next = NULL;
free(p1);
return head;
}
void printlist(struct student *head)
{
struct student * phead;
phead = head->next ;
while(phead)
{
printf("%4d",phead->data);
phead = phead->next;
}
}
main()
{
struct student * mhead;
struct student * jshead;
struct student * oshead;
mhead = creatlist();
printlist(mhead);
jshead = creatlistjs(mhead);
printlist(jshead);
oshead = creatlistos(mhead);
printlist(oshead);
}
大体思路对了,具体的实现还有点问题,楼主可以自己改改
给你个算法,就是复制两份,然后一份按照奇数删除结点一份按照偶数删除结点。就完成了。