wen312645732 发表于 2013-11-19 11:16:46

课后练习

magic[mag·ic || 'mædʒɪk]
n.魔术, 魔法

adj.魔术的; 不可思议的; 有魔力的

wen312645734 发表于 2013-11-19 11:16:47

!!!!!我来啦

fishczhc86 发表于 2013-11-21 00:42:09

{:1_1:}。。。

zch463170098 发表于 2013-11-30 15:04:27

#include<stdio.h>
#include<malloc.h>
#define NULL 0
#define LEN sizeof(List)
typedef struct node
{
    int data;
    struct node * next;
}List;
int n=0;
List *create(void)
{
    List * head;
    List * p1,* p2;
    p1=(List*)malloc(LEN);
    p2=(List*)malloc(LEN);
    head=NULL;
    puts("请输入要插入链表的数据(输入0结束):\n");
    scanf("%d",&p1->data);
    while(p1->data!=0)
    {
      n++;
      if(n==1)
            head=p1;
      else
            p2->next=p1;
      p2=p1;
      p1=(List*)malloc(LEN);
      scanf("%d",&p1->data);
    }
    free(p1);
    p2->next=NULL;
    return head;
}
void Print(List * head)
{
    List * p;
    p=head;
    if(head!=NULL)
      do
      {
            printf("[%d]->",p->data);
            p=p->next;
      }while(p!=NULL);
}
int main()
{
      int m;
      List * head;
      List * pa=(List*)malloc(LEN), *pb=(List*)malloc(LEN);
    List * p1,*p2;
    head=create();
    Print(head);
    printf("\n");
      
    p1=head;
    pa=p1;
    p2=p1->next;
    pb=p2;
      while(p2->next!=NULL)
    {
      p1->next=p1->next->next;
      p1=p2->next;
      if(p1->next==NULL)
            break;
      p2->next=p2->next->next;
      p2=p1->next;
    }
    p1->next=NULL;
    p2->next=NULL;
    Print(pa);
    printf("NULL\n");
    Print(pb);
    printf("NULL\n");
    //return 0;
      scanf("%d", &m);
}
页: [1]
查看完整版本: 课后练习