#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 ==