RP� 2019-07-17 12:04 采纳率: 50%
浏览 303
已采纳

此代码为别人发给我做一个电子词典,但是用的顺序结构非告诉我用的链式?是我看不出来吗,望大佬解答

以下代码有使用链式结构?有构造bst进行增删改查?

#include "stdio.h"

#include "conio.h"

#include "string.h"
#include "stdlib.h"
#define clrscr() system("cls") /*将TC下的清屏函数替换为VC下的清屏函数*/
typedef struct {
char a[20];

char b[40];
}XYZ;
XYZ xyz[50];
void init() /*初始化函数*/
{
int i;
FILE fp;

for (i = 0; i<50; i++)
{
memset(xyz[i].a, '\0', 20); /
清空磁道,*/

memset(xyz[i].b, '\0', 40);
}
fp = fopen("C:\Users\1452983751\Desktop\my.txt", "w"); /*在C盘新建一个TXT文件*/

fp = fopen("C:\Users\1452983751\Desktop\my.txt", "r"); /*将新建的TXT文件打开*/

i = 0;
while (fscanf(fp, "%s %s\n", xyz[i].a, xyz[i].b) != EOF) /*由文件向结构体数组中写数锯*/
i++;
fclose(fp);
}
void find() /*单词查询函数*/
{
int i;
char temp[20];

clrscr();
printf("please input a word:");
scanf("%s", temp);
for (i = 0; i<50; i++)
if (strcmp(temp, xyz[i].a) == 0) /*通过比较字符查询*/
{
printf("\n\n%s : %s", xyz[i].a, xyz[i].b);

printf("\n\npress any key to return");

getch(); return;
}
printf("\n\nnot found");
getch();

return;
}
void add() /*词条录入函数*/
{
int i, j;
char temp[20]; char temp1[40]; clrscr();
for (i = 0; i<50; i++)
{
if (!(*xyz[i].a)) /*找到空位*/
{
printf("\n\nplease input the word:");

scanf("%s", temp);
for (j = 0; j<50; j++)
if (strcmp(temp, xyz[j].a) == 0) /*找到相同字符*/
{
printf("\n\nthe word is already store\n\n");

printf("please any key to return");

getch();

return;
}
printf("\n\nplease input the mean:");

scanf("%s", temp1);
strcpy(xyz[i].a, temp); /*复制*/

strcpy(xyz[i].b, temp1);

return;
}
}
printf("\n\nsorry,the data is full");
}

void del() /*词条删除函数*/
{
int i;
char temp[20];

clrscr();
printf("\n\nplease input the word:");

scanf("%s", temp);

for (i = 0; i<50; i++)
if (strcmp(temp, xyz[i].a) == 0) /*比较*/
{
memset(xyz[i].a, '\0', 20); /*清空该结构体*/

memset(xyz[i].b, '\0', 40);
printf("\n\nsuccess,press any key to return");

getch();

return;
}
printf("\n\nnot found");

getch();

return;
}
void modify() /*词条修改函数*/
{
int i;
char temp[20];

char temp1[40];

clrscr();
printf("\n\nplease input the word:");

scanf("%s", temp);

for (i = 0; i < 50; i++)
if (strcmp(temp, xyz[i].a) == 0)
{
printf("\n\nfound\n\n");
printf("%s : %s\n\n", xyz[i].a, xyz[i].b); /*显示原有单词和意思*/
printf("\n\nplease input the new mean:");

scanf("%s", temp1);
strcpy(xyz[i].b, temp1); /* 从temp1复制结构体中*/
printf("\n\nsuccess,please any key to return");

getch();
return;

    }
printf("\n\nnot found");       
getch();     
return;

}
void view() /*信息显示函数*/ {
int i, j; clrscr();
for (i = 0, j = 0; i<50; i++) {
if (*xyz[i].a != '\0') /*如果不是空位*/ {
j++;
printf("%s : %s\n", xyz[i].a, xyz[i].b);
if (j == 20) /*分页显示,一次显示20页*/ {
j = 0;
printf("\nprease any key to page down"); getch(); clrscr();
}
}
}
printf("\n\nthat's all"); getch();
}
void store() /*信息保存函数*/ {
int i; FILE fp;
fp = fopen("C:\Users\1452983751\Desktop\my.txt", "w"); /
以读的方式再新建my.txt文档*/ if (fp == NULL) /*没建成显示wrong!*/ printf("wrong!"); getchar();
for (i = 0; i < 50; i++)
fprintf(fp, "%s %s\n", xyz[i].a, xyz[i].b); /*将结构体中的数剧保存到my.txt文档*/ fclose(fp);
printf("\n\nstore success\n\n"); getch(); return;

}

int main(void) /*主函数在哪更改字符格式*/ {
char key; init(); while (1) {
clrscr();
printf("\n\n\n 电子英文词典\n\n");
printf("\n************************************************************************\n");
printf(" * 1、单词查询 * \n");
printf(" * 2、词条录入 * \n");
printf(" * 3、词条删除 * \n");
printf(" * 4、词条修改 * \n");
printf(" * 5、信息显示 * \n");
printf(" * 6、信息保存 * \n");
printf(" * 7、退出系统 * \n");
printf("\n************************************************************************\n"); printf("\n\n\n 非本人授权严禁分享!"); key = getch(); switch (key) {
case '1':find(); break; case '2':add(); break; case '3':del(); break; case '4':modify(); break; case '5':view(); break; case '6':store(); break; case '7': return 0;
}
}
return 0;
}

  • 写回答

1条回答 默认 最新

  • threenewbee 2019-07-17 13:37
    关注

    (1)你的程序使用数组连续存储,没有用链表。
    (2)你的查询部分的代码是find()函数,用的是for循环顺序查找判断,没有用二叉搜索树。

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 python天天向上类似问题,但没有清零
  • ¥30 3天&7天&&15天&销量如何统计同一行
  • ¥30 帮我写一段可以读取LD2450数据并计算距离的Arduino代码
  • ¥15 C#调用python代码(python带有库)
  • ¥15 矩阵加法的规则是两个矩阵中对应位置的数的绝对值进行加和
  • ¥15 活动选择题。最多可以参加几个项目?
  • ¥15 飞机曲面部件如机翼,壁板等具体的孔位模型
  • ¥15 vs2019中数据导出问题
  • ¥20 云服务Linux系统TCP-MSS值修改?
  • ¥20 关于#单片机#的问题:项目:使用模拟iic与ov2640通讯环境:F407问题:读取的ID号总是0xff,自己调了调发现在读从机数据时,SDA线上并未有信号变化(语言-c语言)