接下來我將以一道題目來總結我這乙個星期學習的內容
剛拿到題目時心裡慌兮兮的,這麼恐怖….100分鐘15題,而且要有6種排序,8個輸出
還能不能好好玩耍了. t.t
看過一次題目後 我好像明白點啥了
多看幾次題目後,發現其實老師已經把解題思路&命名問題都給解決了(特別是命名問題),只要按著題目上的順序寫,思路就很清晰了
廢話不說了:**獻上:
#import
#import "teacher.h"
int main(int argc, const
char * argv)
, ,,,
};enum functionname ;
enum functionname a0 = 10;
printf("輸入1:實現按照姓名進行公升序排列\n");
printf("輸入2:實現按照姓名進行降序排列\n");
printf("輸入3:實現按照員工編號進行公升序排列\n");
printf("輸入4:實現按照員工編號進行降序排列\n");
printf("輸入5:實現按照評分進行公升序排列\n");
printf("輸入6:實現按照評分進行降序排列\n");
printf("輸入7:實現輸出所有女老師\n");
printf("輸入8:實現輸出所有男老師\n");
printf("******************************\n");
while (a0 > 8 )
}return
0;}
#import
typedef
struct teacher teacher;
typedef
bool(*comparefunctionpointer) (teacher teacher1, teacher teacher2);
void printteachers(teacher *teachers,int count);
void printteacher(teacher* teacher);
/********************/
void sortteachers(teacher teachers, int count, comparefunctionpointer cfp);
//老師排序,,,,,cfp為排序條件
void prinitteachers(teacher *teachers, int count);
//列印陣列中所有老師的函式
bool comparenamebyascending(teacher teacher1, teacher teacher2);
bool comparenamebydescending(teacher teacher1, teacher teacher2);
//比較姓名的函式
bool comparenumberbyascending(teacher teacher1, teacher teacher2);
bool comparenumberbydescending(teacher teacher1, teacher teacher2);
//比較編號
bool comparescorebyascending(teacher teacher1, teacher teacher2);
bool comparescorebydescending(teacher teacher1, teacher teacher2);
//比較評分
void printmaleteacher(teacher *teachers, int count);
void printfemaleteacher(teacher *teachers, int count);
#import "teacher.h"
//比較姓名的函式
bool comparenamebyascending(teacher teacher1, teacher teacher2);
bool comparenamebydescending(teacher teacher1, teacher teacher2)
//比較編號
bool comparenumberbyascending(teacher teacher1, teacher teacher2);
bool comparenumberbydescending(teacher teacher1, teacher teacher2);
//比較分數
bool comparescorebyascending(teacher teacher1, teacher teacher2);
bool comparescorebydescending(teacher teacher1, teacher teacher2);
//列印教師
void printteacher(teacher* teacher)
void printteachers(teacher *teachers,int count)
}//排序教師
void sortteachers(teacher teachers, int count, comparefunctionpointer cfp)}}
printteachers(teachers, count);
}void printmaleteacher(teacher *teachers, int count)
}}void printfemaleteacher(teacher *teachers, int count)}}
執行結果
這次注釋比較少,不過結構設定的比較簡單,大家可以先看看
new delete 以及結構體的綜合應用
關於new 和 delete的操作 1.運算子叫做 指向結構體成員運算子 是c語言和c 語言的乙個運算子,用處是使用乙個指向結構體或物件的指標訪問其內成員。2.new delete 的使用 僅限於c 注意,new delete不是函式而是操作符!注意與c中的malloc和free區分 程式設計的時候...
結構體,結構體指標作為函式引數的應用筆記
1.結構體,結構體指標作為函式引數有何區別 include include struct animal 使用結構體作為引數 浪費記憶體 需要建立結構體 void change struct struct animal cat 函式內部改變需要位址 所以需要指標儲存 void change point...
結構體指標的應用理解
在cjson呼叫時遇到的結構體引數賦值時的問題,需要cjson 才行,下面兩種方法都行,對比一下。也對指標理解更深入 結構體給函式當形參時,由於主函式裡也沒分配結構體空間,只有結構體的位址,區域性函式裡面只能給區域性結構體位址,給結構體的位址放在結構體位址的空間中,要有存放結構體位址空間的位址,也就...