Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "pch.h"
- #include <iostream>
- #include <string.h>
- #include <windows.h>
- struct Tree {
- char name[30];
- int count = 0;
- Tree *left, *right;
- }*root;
- int kol = 0, kolout = 0;
- int k20 = 0;
- FILE *f;
- void create_Tree(Tree**root, char a[]) {
- if (!(*root)) {
- (*root) = new Tree;
- (*root)->left = NULL;
- (*root)->right = NULL;
- strcpy((*root)->name, a);
- (*root)->count++;
- if ((*root)->count == 1)
- kol++;
- }
- else if (strcmp(a, (*root)->name) < 0)
- create_Tree(&((*root)->left), a);
- else if (strcmp(a, (*root)->name) > 0)
- create_Tree(&((*root)->right), a);
- else {
- (*root)->count++;
- if ((*root)->count == 1)
- kol++;
- }
- }
- void print_Tree(Tree *root) {
- if (root&&k20 < 20) {
- print_Tree(root->left);
- printf("%d ", root->count);
- printf("%s", root->name);
- k20++;
- kolout++;
- print_Tree(root->right);
- }
- if (k20 == 20 || kolout == kol)
- {
- getchar();
- k20 = 0;
- }
- /*if (root)
- goto here;*/
- }
- int main()
- {
- SetConsoleCP(1251);
- SetConsoleOutputCP(1251);
- f = fopen("f.txt", "r");
- char a[30];
- int i = 0;
- i = 0;
- while (!feof(f)) {
- fscanf(f, "%c", &a[i]);
- if (!((a[i] >= 'A'&&a[i] <= 'Z') || (a[i] >= 'a'&&a[i] <= 'z') || (a[i] >= 'А'&&a[i] <= 'Я') || (a[i] >= 'а' && a[i] <= 'п') || (a[i] >= 'р' && a[i] <= 'я'))) {
- a[i] = '\n';
- a[i + 1] = '\0';
- if (i != 0)
- create_Tree(&root, a);
- for (int i = 0; i < 30; i++)
- a[i] = '\0';
- i = 0;
- }
- if (a[0] != '\0')
- i++;
- }
- /*int k;
- scanf("%d", &k);*/
- print_Tree(root);
- fclose(f);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement