?? algo9-1.c
字號:
/* algo9-1.c 檢驗bo9-1.c(順序表部分)的程序 */
#include"c1.h"
#define N 5 /* 數據元素個數 */
typedef int KeyType; /* 設關鍵字域為整型 */
typedef struct /* 數據元素類型(以教科書圖9.1高考成績為例) */
{
long number; /* 準考證號 */
char name[9]; /* 姓名(4個漢字加1個串結束標志) */
int politics; /* 政治 */
int Chinese; /* 語文 */
int English; /* 英語 */
int math; /* 數學 */
int physics; /* 物理 */
int chemistry; /* 化學 */
int biology; /* 生物 */
KeyType key; /* 關鍵字類型應為KeyType,域名應為key,與bo9-1.c中一致 */
} ElemType;
ElemType r[N]={{179324,"何芳芳",85,89,98,100,93,80,47},
{179325,"陳紅",85,86,88,100,92,90,45},
{179326,"陸華",78,75,90,80,95,88,37},
{179327,"張平",82,80,78,98,84,96,40},
{179328,"趙小怡",76,85,94,57,77,69,44}}; /* 全局變量 */
#define total key /* 定義總分(total)為關鍵字 */
#include"c9.h"
#include"c9-1.h"
#include"bo9-1.c"
void print(ElemType c) /* Traverse()調用的函數 */
{
printf("%-8ld%-8s%4d%5d%5d%5d%5d%5d%5d%5d\n",c.number,c.name,c.politics,c.Chinese,c.English,c.math,c.physics,c.chemistry,c.biology,c.total);
}
void main()
{
SSTable st;
int i,s;
for(i=0;i<N;i++) /* 計算總分 */
r[i].total=r[i].politics+r[i].Chinese+r[i].English+r[i].math+r[i].physics+r[i].chemistry+r[i].biology;
Creat_Seq(&st,N); /* 由全局數組產生靜態查找表st */
printf("準考證號 姓名 政治 語文 外語 數學 物理 化學 生物 總分\n");
Traverse(st,print); /* 按順序輸出靜態查找表st */
printf("請輸入待查找人的總分: ");
scanf("%d",&s);
i=Search_Seq(st,s); /* 順序查找 */
if(i)
print(*(st.elem+i));
else
printf("沒找到\n");
Destroy(&st);
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -