重庆分公司,新征程启航
为企业提供网站建设、域名注册、服务器等服务
由于本案例是基于链表与结构体的设计
首先定义链表节点:
typedef struct Node
{char word[20]; //单词
char Chinese[40]; //中文
struct Node *next; // 指针域
} node;
node list; // 链表
增加单词信息(本质上是单链表的增加节点操作):
// 增加单词信息
void Add_Printf()
{system("cls");
node st;
printf("请输入新增单词的相关信息:\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);
}
删除单词信息(本质上与单链表的删除节点操作一致):
// 删除单词
void Delete_Printf(node *L)
{system("cls");
char Chinese[40];
node *p;
printf("请输入要删除的单词的中文意思:");
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);
}
修改单词信息(先根据输入的中文查找到相应的单词信息,然后进行修改):
// 修改单词信息
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("是否继续修改?(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");
}
}
// 按中文进行查找
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");
}
完整代码请点击此处获取
你是否还在寻找稳定的海外服务器提供商?创新互联www.cdcxhl.cn海外机房具备T级流量清洗系统配攻击溯源,准确流量调度确保服务器高可用性,企业级服务器适合批量采购,新人活动首月15元起,快前往官网查看详情吧