當前位置:法律諮詢服務網 - 中國稅務 - C語言鏈表 要求:按職稱級別由高到低排序,並統計各職稱人數及各院系各職稱人數.寫出統計函數和主函數.急

C語言鏈表 要求:按職稱級別由高到低排序,並統計各職稱人數及各院系各職稱人數.寫出統計函數和主函數.急

湊個熱鬧

#include "stdio.h"

#include "malloc.h"

#include "string.h"

#define N 7

typedef struct node

{

char num[3]; /*教室的編號*/

char name[9]; /*教師的姓名*/

char sex[5]; /*教師的性別*/

char prof[6]; /*教師的職稱*/

char dept[10]; /*教師所在院系*/

struct node * link;

}teacher;

void fun_count_prof( teacher *head )

{

teacher *p=head->link ;

char prof[6]="";

int cnt=0;

while (p)

{

if ( strcmp(prof,p->prof) )

{

if ( prof[0] )

printf("prof:%s cnt=%d\n" , prof , cnt );

//統計下壹職稱

cnt=0;

strcpy(prof,p->prof) ;

}

cnt++;

p=p->link ;

}

if ( prof[0] )

printf("prof:%s cnt=%d\n" , prof , cnt ) ;

}

void fun_count_dept_prof( teacher *head )

{

teacher *p=head->link ;

char prof[6]="";

char dept[10]="";

int cnt=0;

while (p)

{

//檢查職稱變化

if ( strcmp(prof,p->prof) )

{

if ( prof[0] )

printf("dept:%s prof:%s cnt=%d\n" , dept , prof , cnt ) ;

//統計下壹職稱

cnt=0;

strcpy(dept,p->dept) ;

strcpy(prof,p->prof) ;

}

//檢查院系變化

if ( strcmp(dept,p->dept) )

{

//輸出上壹院系的最後壹個統計

printf("dept:%s prof:%s cnt=%d\n" , dept , prof , cnt ) ;

//統計下壹院系

cnt=0;

strcpy(dept,p->dept) ;

}

cnt++;

p=p->link ;

}

if ( prof[0] )

printf("dept:%s prof:%s cnt=%d\n" , dept , prof , cnt ) ;

}

void crt_link( teacher *head )

{

//模擬數據:要求數據按職稱由高到低,職稱下按部門排序,方便統計

struct teach_er

{

char num[3]; /*教室的編號*/

char name[9]; /*教師的姓名*/

char sex[5]; /*教師的性別*/

char prof[6]; /*教師的職稱*/

char dept[10]; /*教師所在院系*/

} stTeacher[N]={

{"01","name0","male","prof0" , "mac"},

{"02","name1","male","prof0" , "com"},

{"03","name2","male","prof0" , "com"},

{"04","name3","male","prof1" , "mac"},

{"05","name4","male","prof1" , "mac"},

{"06","name5","male","prof1" , "com"},

{"07","name6","male","prof2" , "com"},

};

teacher *tail=head , *p ;

int i=0;

for ( i=0;i<N;i++ )

{

p=malloc(sizeof(teacher) );

strcpy(p->num,stTeacher[i].num );

strcpy(p->name,stTeacher[i].name );

strcpy(p->sex,stTeacher[i].sex );

strcpy(p->prof,stTeacher[i].prof );

strcpy(p->dept,stTeacher[i].dept );

p->link=NULL ;

tail->link=p;

tail=p;

}

}

int main()

{

teacher *head;

head=malloc( sizeof(teacher) );

head->link=0;

crt_link( head );

fun_count_prof( head );

fun_count_dept_prof( head );

return 0;

}

  • 上一篇:稅務內部控制自查工作方案
  • 下一篇:企業的五證是什麽?
  • copyright 2024法律諮詢服務網