我的第一部作品

来源:互联网 发布:720云全景软件 编辑:程序博客网 时间:2024/05/16 18:31
#include<stdio.h>
#include
<malloc.h>
#define LEN sizeof(struct student)
#include
<stdlib.h>
struct student
{long num;
 
char name[10];
 
float score;
 
struct student *next;
 }
;

   
int n;
   
struct student *creat(void)
   
{struct student *p,*q;
   
int i=0;
   n
=1;
    q
=(struct student *)malloc(LEN);
    q
->num=100;
    q
->next=NULL;
    
for(i=1;i<=5;i++)
     
{p=(struct student *)malloc(LEN);
      scanf(
"%ld,%s,%f",&p->num,p->name,&p->score);
       p
->next=q->next;
       q
->next=p;
       n
++;
       }

       
return(q);
       }



       
void print(struct student *q)
       
{struct student *p;
       printf(
"there are %d student in the list ,they are: ",n);
       p
=q;
       
if(q!=NULL)
       
do{
         printf(
"%ld%s%.2f ",p->num,p->name,p->score);
         p
=p->next;
         }
while(p!=NULL);
         }



         
struct student *insert(struct student *q,int i)
         
{struct student *p,*s;
         
int j=0;
         p
=q;
         
while(p&&j<(i-1)) {p=p->next;j++;}
         
if(!p||j>i-1) printf("wrong,input again");
          
else
         
{ printf("input the student's message which you want to insert: ");
         s
=(struct student *)malloc(LEN);
         scanf(
"%ld,%s,%f",&s->num,s->name,&s->score);
         s
->next=p->next;
         p
->next=s;
         n
=n+1;
         }

         
return(p);
         }




         
struct student *search(struct student *q,int i)
         
{struct student *p;
         
int j=1;
         p
=q;
         
while(p&&j<i)
         
{p=p->next;
         j
++;
         }

         
if(!p||j>i)
         printf(
"error!");
         
else
           
{printf("the number of %d student's message are: ",i);
         printf(
"%ld,%s,%.2f ",p->num,p->name,p->score);}

         }




         
struct student *deleted(struct student *L,int i)
         
{struct student *p,*q;
          
int j=0;
          p
=L;
          
while(p->next&&j<(i-1))
          
{p=p->next;
          j
++;}

          
if(!(p->next)||j>(i-1)) printf("error!");
          q
=p->next;
          p
->next=q->next;
          printf(
"the num of %ld studnet was deleted: ",q->num);
          n
=n-1;
          }


int main()
{struct student *head,*stu;
 
int i,j;
printf(
"************** ");
 printf(
"************** ");
 
for(i=1;i<=4;i++)
 
{
  
for(j=1;j<=4-i;j++)
 printf(
" ");
  
for(j=1;j<=(2*i-1);j++)
  printf(
"*");
      printf(
" ");
 }

 
for(i=4;i>=1;i--)
 
{
 
for(j=1;j<=4-i;j++)
 printf(
" ");

for(j=1;j<=(2*i-1);j++)
printf(
"*");

printf(
" ");
}

printf(
"************** ");
printf(
"************** ");

printf(
"input the student's message:num,name,score(end with 0,0,0) ");
 head
=creat();
 print(head);
 printf(
" ");
 
printf(
"    1-charu ");
printf(
"    2-shanchu ");
printf(
"    3-chazhao ");
printf(
"    4-dayin ");

 printf(
"input a number(1-4) to make a choose ");
 scanf(
"%d",&i);
 
switch(i)
 
case 1:printf("input before which studnet you want to insert: ");
      scanf(
"%d",&i);
      
while(i)
      
{head=insert(head,i);
      print(head);
       printf(
"input before which studnet you want to insert: ");
       scanf(
"%d",&i);
      }
 break;
    
case 2:printf("which number of the student do you want to deleted: ");
       scanf(
"%d",&i);
       
while(i)
       
{head=deleted(head,i);
        print(head);
        printf(
"which number of the stuent do you want to deleted: ");
        scanf(
"%d",&i);
       }

          
break;
     
case 3:printf("which number of the student do you want to search: ");
        scanf(
"%d",&i);
        
while(i)
        
{head=search(head,i);
         print(head);
         printf(
"which of the studnet do you want to search: ");
         scanf(
"%d",&i);
        }
   break;
     
case 4:print(head);  break;
     
default :printf("the number you input are wrong: ");
    }

    system(
"pause");
    
return 0;
    }

 
原创粉丝点击