由于本案例是基于鏈表與結(jié)構(gòu)體的設(shè)計(jì)
首先定義鏈表節(jié)點(diǎn):
typedef struct Node
{char word[20]; //單詞
char Chinese[40]; //中文
struct Node *next; // 指針域
} node;
node list; // 鏈表
增加單詞信息(本質(zhì)上是單鏈表的增加節(jié)點(diǎn)操作):
// 增加單詞信息
void Add_Printf()
{system("cls");
node st;
printf("請輸入新增單詞的相關(guān)信息:\n");
printf("英文:");
scanf("%s", &st.word);
printf("中文:");
scanf("%s", st.Chinese);
Add(&list, st);
}
void Add(node *L, node e)
{// 頭插法
node *p = L;
node *s = (node *)malloc(sizeof(node));
*s = e;
s->next = p->next;
p->next = s;
// Save_FILE(L);
}
刪除單詞信息(本質(zhì)上與單鏈表的刪除節(jié)點(diǎn)操作一致):
// 刪除單詞
void Delete_Printf(node *L)
{system("cls");
char Chinese[40];
node *p;
printf("請輸入要?jiǎng)h除的單詞的中文意思:");
scanf("%s", Chinese);
node *st = Search_Chinese(Chinese, L);
p = st;
if (st == NULL)
{printf("查無此單詞!\n");
return;
}
st = st->next;
printf("________________________________________________________________\n");
printf("|單詞\t\t|中文\t\t|\n");
printf("________________________________________________________________\n");
printf("|%s\t\t|%s\t\t|\n", st->word, st->Chinese);
printf("________________________________________________________________\n");
Delete(p);
// 保存信息
// Save_FILE(L);
}
void Delete(node *s)
{node *t = s->next;
s->next = t->next;
t->next = NULL;
free(t);
}
修改單詞信息(先根據(jù)輸入的中文查找到相應(yīng)的單詞信息,然后進(jìn)行修改):
// 修改單詞信息
void Fix(node *L)
{system("cls");
char Chinese[40];
printf("請輸入要修改的單詞的中文意思:");
scanf("%s", &Chinese);
node *st = Search_Chinese(Chinese, L);
if (st == NULL)
{printf("查無此單詞!\n");
return;
}
st = st->next;
int choice = 0;
while (1)
{system("cls");
// 輸出一次所要修改的單詞
printf("________________________________________________________________\n");
printf("|單詞\t\t|中文\t\t|\n");
printf("________________________________________________________________\n");
printf("|%s\t\t|%s\t\t|\n", st->word, st->Chinese);
printf("________________________________________________________________\n");
printf("修改單詞 ---- 1\n");
printf("修改中文 ---- 2\n");
printf("請輸入要修改的信息:");
scanf("%d", &choice);
switch (choice)
{case 1:
printf("請輸入單詞:");
scanf("%s", st->word);
break;
case 2:
printf("請輸入中文:");
scanf("%s", st->Chinese);
break;
}
printf("是否繼續(xù)修改?(Yes:1 / No:0):");
scanf("%d", &choice);
if (choice == 0)
{ break;
}
}
// 修改完成后該單詞的信息
printf("________________________________________________________________\n");
printf("|單詞\t\t|中文\t\t|\n");
printf("________________________________________________________________\n");
printf("|%s\t\t|%s\t\t|\n", st->word, st->Chinese);
printf("________________________________________________________________\n");
}
按中文查詢單詞信息:
// 查詢單詞信息
void Search_Printf(node *L)
{system("cls");
char Chinese[40];
node *st;
printf("請輸入要查詢的單詞的中文意思:");
scanf("%s", Chinese);
st = Search_Chinese(Chinese, L);
if (st == NULL)
{printf("查無此單詞!\n");
}
else
{st = st->next;
printf("________________________________________________________________\n");
printf("|單詞\t\t|中文\t\t|\n");
printf("________________________________________________________________\n");
printf("|%s\t\t|%s\t\t|\n", st->word, st->Chinese);
printf("________________________________________________________________\n");
}
}
// 按中文進(jìn)行查找
node *Search_Chinese(char name[], node *L)
{node *p = L;
while (p->next != NULL)
{if (strcmp(name, p->next->Chinese) == 0)
{ return p;
}
p = p->next;
}
return NULL;
}
輸出單詞信息:
// 輸出單詞信息
void Print(node *L)
{system("cls");
node *p = L->next;
Print_Printf();
if (p != NULL)
{while (p != NULL)
{ printf("________________________________________________________________\n");
printf("|%s\t\t|%s\t\t|\n", p->word, p->Chinese);
printf("________________________________________________________________\n");
p = p->next;
}
}
}
void Print_Printf()
{printf("________________________________________________________________\n");
printf("|單詞\t\t|中文\t\t|\n");
printf("________________________________________________________________\n");
}
完整代碼請點(diǎn)擊此處獲取
你是否還在尋找穩(wěn)定的海外服務(wù)器提供商?創(chuàng)新互聯(lián)www.cdcxhl.cn海外機(jī)房具備T級流量清洗系統(tǒng)配攻擊溯源,準(zhǔn)確流量調(diào)度確保服務(wù)器高可用性,企業(yè)級服務(wù)器適合批量采購,新人活動首月15元起,快前往官網(wǎng)查看詳情吧