实验三:基于线性表和二叉排序树的低频词过滤系统(源码)

#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdlib.h>
#include<malloc.h>
#include<string.h>
#include <time.h>
typedef struct node1 {        //单链表节点 
    char data[20];
    int count;
    struct node1* next;
}LNode, * LinkList;
typedef struct node2//排序二叉树节点 
{
    char data[20];
    int count;
    struct node2* left;
    struct node2* right;
}BSTNode, * BSTree;
BSTree T, nT;
typedef struct stack//非递归中序遍历写入文件outFile.txt 
{
    BSTree data[1000];
    int top;
}seqstack;
/***************************************************************************************///单链表 
void swap(LinkList x, LinkList y)
{
    char a[20];
    strcpy(a, x->data);
    int b = x->count;

    strcpy(x->data, y->data);
    x->count = y->count;

    strcpy(y->data, a);
    y->count = b;
}
void sort_slist(LinkList& L)
{
    LinkList p, q, temp;
    p = L->next;
    while (p)
    {
        q = p->next;
        while (q)
        {
            if (p->count < q->count)
            {
                swap(p, q);
            }
            else
                q = q->next;
        }
        p = p->next;
    }
}
void InitList(LinkList& L)
{
    L = (LinkList)malloc(sizeof(LNode));
    L->next = NULL;
}
void InsertList(LinkList& L, char* a)//先将每一元素存入线性链表中,然后统计个数 
{
    int flag = 0;
    LinkList P;
    LinkList Q;
    Q = L->next;
    while (Q != NULL)
    {
        if (!strcmp(a, Q->data))
        {
            Q->count++;
            flag = 1;
            break;
        }
        Q = Q->next;
    }
    if (!flag)
    {
        P = (LinkList)malloc(sizeof(LNode));
        strcpy(P->data, a);
        P->count = 1;
        P->next = L->next;
        L->next = P;

    }
}
void LNodeprint(LinkList& L)
{
    LinkList P;
    P = L->next;
    printf("单词       个数统计\n");
    while (P != NULL)
    {
        printf("%-10s    %d\n", P->data, P->count);
        P = P->next;
    }
}
void fprint1(LinkList& L)
{
    LinkList P;
    FILE* out;
    out = fopen("outFile.txt", "a+");//建立输出文件
    fprintf(out, "单链表删除个数<5的单词:\n");
    P = L->next;
    while (P)
    {
        fprintf(out, "%s (%d)\t", P->data, P->count);
        P = P->next;
    }
    fclose(out);
}
void single_distinguish_count1()
{
    FILE* in;
    char a[20], c;
    LinkList L;
    InitList(L);
    in = fopen("inFile.txt", "r");//打开输入文件

    while (!feof(in))//直到碰见文件结束符结束循环
    {
        int i = 0;
        memset(a, 0, sizeof(a));
        while ((c = fgetc(in)) != EOF && !(c == ',' || c == '.' || c == '!' || c == '?' || c == 

  • 0
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值