Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<stdlib.h>
- typedef struct cvor_s {
- struct cvor_s* left;
- struct cvor_s* right;
- char c;
- int value;
- } cvor;
- cvor *insert(cvor *root,char c) {
- cvor *novi;
- int korijenJeNov = 0;
- if (root == NULL) {
- korijenJeNov = 1;
- root = (cvor *) malloc(sizeof(cvor));
- root->c = c;
- root->value = 1;
- root->right = NULL;
- root->left = NULL;
- }
- if (root->c == c && korijenJeNov == 0) {
- root->value += 1;
- }
- if (root->c < c) {
- root->right = insert(root->right,c);
- }
- if (root->c > c) {
- root->left = insert(root->left,c);
- }
- return root;
- }
- void inorder(cvor *root) {
- if (root == NULL) return;
- inorder(root->left);
- printf("Broj ponavljanja znaka \'%c\': %d.\n",root->c,root->value);
- inorder(root->right);
- }
- int main (void) {
- FILE *file;
- char znak;
- cvor *root = NULL;
- file = fopen("mirko.txt","r");
- if (file == NULL) {
- printf("lazanje");
- }
- while ((znak = fgetc(file)) != EOF) {
- root = insert(root,znak);
- }
- inorder(root);
- fclose(file);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement