Article View: cn.bbs.comp.program
Article #2385Re: [ת��] �������⣡
From: lucky
Date: Fri, 26 Dec 1997 00:00
Date: Fri, 26 Dec 1997 00:00
117 lines
3640 bytes
3640 bytes
��֮�� wrote:
>
> [1;37m�� ��������ת���� [32mDatabase [37m������ ��
> �� ԭ����[32m Tony[37m ��� ��[m
> ���Ǹտ�ʼѧϰC���ԣ�����ѧ���ṹ�壬����һ���ⲻֻ��ν���������ǽ���
> �ļ�ʱ���ֶ������Non-portable poiner assign ment in function main.
> Դ��������:
> #define NULL 0
> #define LEN sizeof(struct student)
> struct student
> {long num;
> float score;
> struct student *next;
> };
> int n;
>
> main()
> {
> struct student *head,stu;
> long del_num;
> printf("imput records:\n");
> head=creat();
> print(head);
> printf("\input the deleted number:");
> scanf("%ld",&del_num);
> head=del(head,del_num);
> print(head);
> printf("\nimput the imserted record:");
> scanf("%ld,%f",&stu.num,&stu.score);
> head=imsert(head,&stu);
> print(head);
> }
>
> struct student *creat()
> {struct student *head;
> struct student *p1,*p2;
> n=0;
> p1=p2=(struct student *)malloc(LEN);
> scanf("%ld,%f",p1->num,&p1->score);
> head=NULL;
>
> while (p1->num!=0)
> { n=n+1;
> if (n==1) head=p1;
> else p2->next=p1;
> p2=p1;
> p1=(struct student *)malloc(LEN);
> scanf("%ld,%f",&p1=->num,&p1->score);
> }
> p2->next=NULL;
> return(head);
>
> void print(head)
> struct student *head;
> {struct student *p;
> printf ("\nNow,These %d records are:\n",n);
> p=head;
> if (head!=NULL)
> do
> { printf("%ld %5.1f\n",p->num,p->score);
> p=p->next;
> }while (p!=NULL);
> }
>
> struct student *del(head,num)
> struct student *head;
> long num;
> {struct student *p1,*p2;
> if (head==NULL) {printf("\nlist null!\n");goto end;}
> p1=head;
> while (num!=p1->num&&p1->next!=NULL)
> { p2=p1;p1=p1->next;}
> if (num==p1->num)
> { if (p1==head) head=p1->next;
> else p2->next=p1->next;
> printf("delete:%ld\n",num);
> n=n-1;
> }
> else printf("%ld not been found!\n",num);
>
> end:
> return(head);
> }
>
> struct student *inser(head,stud)
> struct student *head,stud;
> {struct student *p0,*p1,*p2;
> p1=head;
> p0=stud;
> if (head==NUll)
> {head=p0;p0->next=NULL;}
> else
> while ((p0->num>p1->num)&&(p1->next!=NULL))
> {p2=p1;p1=->next;}
> if (p0->num<=p1->num)
> {if (head==p1) head=p0;
> else {p2->next=p0;
> p0->next=p1;}
> }
> else
> {p1->next=p0;p0->next=NULL;}
> n=n+1;
> return(head);
> }
>
> --
> [m[1;34m�� ��Դ:����ɽBBS����վ bbs.fs.gnet.cn��[FROM: bbs.fs.gnet.cn][m
>
> --
> [m[1;35m�� ת��:���ɽBBS����վ bbs.fs.gnet.cn��[FROM: bbs.fs.gnet.cn][m
����û������˵��, ��������У�
1����main()��ǰ�棬��������(����main()����)������ӳ�������˵��, �磺
struct student *creat()��
2. ��main()�����Ƶ�����ĩβ
Technical Details
Message-ID:
<34A327D9.38E8@nobsys.com>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<3Lc4eQ$UPc@bbs.fs.gnet.cn>Show Full Headers
Complete Article Headers
X-Google-Language: Chinese,GB X-Google-Thread: fc86e,9bee37598e74239d,start X-Google-Attributes: gidfc86e,public From: lucky <qh.lu@nobsys.com> Subject: Re: [ת��] �������⣡ Date: 1997/12/26 Message-ID: <34A327D9.38E8@nobsys.com> X-Deja-AN: 310228319 Content-Transfer-Encoding: 8bit References: <3Lc4eQ$UPc@bbs.fs.gnet.cn> Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Organization: Net Ease Newsgroups: cn.bbs.comp.program