feierin365的空间
feierin365 长沙 在线状态
35次访问,排名46308好友2人,关注者1
比较喜欢JAVA
注册时间:2007-10-15
登录时间:2008-6-29
[加为好友] [即时聊天] [发私信]
feierin365的个人资料
所在行业:计算机软件
社区头衔:
个人专长:
java
专家分: 目前总共有0分
博客:目前总共有1条评论
访问量:32
排名:20000名之外
文章数:2条
feierin365的好友
feierin365的留言
frydsh发表于:2007-12-04
#include "stdio.h"
#include "stdlib.h"
#define null 0
struct node//数据节点
 {
  int num;
  struct node *next;//指向下一个数据节点
 };
 struct head//管理一个数据链的头节点
{
 struct node *next;//指向数据链的第一个节点
 struct node *last;//指向数据链的最后一个节点
};
 
 void main()
 {
  struct head *copyp(int new_nth,int number,struct node *p);//将数number插入到指针p指向的一列数中,排第new_nth,代码在最后,此函数经检验运行正确.
  struct node *a,*b;
  a=(struct node *)malloc(sizeof(struct node));
  a->num=1;
  a->next=null;
  b=(struct node *)malloc(sizeof(struct node));
  b->num=2;
  b->next=a;//把a,b作为一组连起来,b在前面

  struct head s;
  struct node *p;
  s.next=(copyp(1,7,b))->next;
  s.last=(copyp(1,7,b))->last;
  s.last->next=(copyp(2,7,b))->next;
  s.last=(copyp(2,7,b))->last;
  s.last->next=(copyp(3,7,b))->next;
  s.last=(copyp(3,7,b))->last;
 
  p=s.next;
  int e=0;
  do//3个数一行的输出数据
  {
   printf("%d ",p->num);
   e  ;
   if(e%3==0)
   printf("\n");
   
   p=p->next;
   
  }
  while(p!=null);
}



struct head *copyp(int new_nth,int number,struct node *p)//将数number插入到一列数中,排第new_nth.
{
 struct head *head_a;
 head_a=(struct head *)malloc(sizeof(struct head));
 head_a->last=null;
 head_a->next=null;
 struct node *xp;
 struct node *new_node;
 new_node=(struct node *)malloc(sizeof(struct node));
 new_node->num=number;
 new_node->next=null;
 int k=0;
 while(p!=null)
 {
  if(k==0)
  {
   if(new_nth==1)
   {
    head_a->next=new_node;
head_a->last=new_node;
k  ;
   }
   else
   {
    xp=(struct node *)malloc(sizeof(struct node));
xp->num=p->num;
xp->next=null;
head_a->next=xp;
head_a->last=xp;
    p=p->next;
    k  ;
   }
  }
  else 
  {
   if(k!=new_nth-1)
   {
xp=(struct node *)malloc(sizeof(struct node));
xp->num=p->num;
xp->next=null;
    (head_a->last)->next=xp;
    head_a->last=xp;
    p=p->next;
    k  ;
   }
   else
   { 
    (head_a->last)->next=new_node;
    head_a->last=new_node;
k  ;
   }
  }
 }
  return head_a;
}
/*我想看到的结果是7 2 1
                  2 7 1
  2 1 7
此程序按理应该输出3行数,但是却只有一行7 2 1,不知道是怎么回事 求达人解决*/

给feierin365的留言
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|版权声明|问题报告
北京创新乐知广告有限公司 版权所有, 京 ICP 证 070598 号
世纪乐知(北京)网络技术有限公司 提供技术支持
Copyright © 2000-2007, CSDN.NET, All Rights Reserved
GongshangLogo