C

数据结构-C复习-学生成绩表-链表

linked based student list

Posted by xuepro on November 9, 2017

原理请观看数据结构视频课程的“网易云课堂”“腾讯课堂”

链表 (// copyright by hwdong)

#include "cstring"
#include "malloc.h"
#include "cstdio"


typedef struct{
   char name[30];
   float score;
} student;


struct LNode{
  student data; //Type data;
  LNode *next;
} ;

void In_student(student &s){
   scanf("%s",s.name);
   scanf("%f",&(s.score));
}
void Out_student(const student s){
  printf("name:%s  score:%3.2f\n",
           s.name, s.score);
}


void copy_stu(student &d, const student &s){ 
  strcpy((char *)d.name,(char *)s.name);
  d.score = s.score;   
}


int main(){
  student s;   int i = 0,j = 0,k=0 ;
  LNode *q = 0,*p =(LNode *)malloc(sizeof(LNode));
  p->next = 0;
  do{
     printf("请输入学生姓名和分数:\n");
     In_student(s);  
     if(s.score>=60)  j++;  
     else if(s.score<0) break;
     q = (LNode *)malloc(sizeof(LNode));
     q->next  = p->next;
     copy_stu(q->data,s);
     p->next = q;
  }while(s.score>=0);
  
  q = p->next;
  while(q) {   Out_student(q->data); q = q->next;}
  printf("num of passed:%d\n",j);

  return 0;
}

支付宝打赏 微信打赏

您的打赏是对我最大的鼓励!