Google Answers Logo
View Question
 
Q: Trees ( No Answer,   0 Comments )
Question  
Subject: Trees
Category: Computers > Programming
Asked by: james05-ga
List Price: $40.00
Posted: 09 Oct 2005 16:45 PDT
Expires: 10 Oct 2005 19:15 PDT
Question ID: 578299
Hi,

I'm trying to compare the processing times of a linked list versus a
binary tree.  I've previously coded the linked list for this task. 
I have begun coding the binary tree, but am stuck as I am new to
binary trees.  I have coded the outline, but
the core parts of the program to make the binary tree work are
missing.  Can anyone help (I've commented where I need help at and
what needs to be inserted.  I know what needs to be put there, just
don't know the syntax or format)?  The program is meant to take input
from a text file and provide word counts such as total words, most
frequent words, etc.

Note:  I'm self-teaching myself C and none of my co-workers could 
help me, except for the basic layout and I was hoping I could find
someone more knowledgable here.  Once I finish this, I can have a
definitive example to teach myself with other than basic tutorials
that aren't helping me much.
The code is below (please do not create new variables if possible,
these are similar to my original linked list program and would help me
understand better).

Thank you for your help.


#include <stdio.h>
#include <malloc.h>
struct nodes {			// specify the "shape" of a nodes structure ...
	struct nodes *left;	// the left and right branch pointers
	struct nodes *right;
	int count;		// word count 
	char *word;		// a pointer to the word
} *root;			// declare the root pointer variable

struct nodes **search(struct nodes **, char *);
void statistics(struct nodes *);
int get_word(char *);

int total_of_nodes, total_words, high;
struct nodes *most_frequent;

int main(int argc, char *argv[]) {
	struct nodes **tpp;
	char word_buff[100];	// the reusable word buffer
	int i;
	while(get_word(word_buff)) {
		tpp = search(&root, word_buff);
		/****Code here to add any new nodes and count the repeats***/
		
		
	}
	statistics(root);
	printf("total_of_nodes %d\n", total_of_nodes);
	printf("total_words %d\n", total_words);
	if(most_frequent)
		printf("most frequent word <%s> count is %d\n",
			most_frequent->word, most_frequent->count);
	for(i = 1; i < argc; i++) {
		tpp = search(&root, argv[i]);
		if((*tpp) == NULL)
			printf("%s is NOT in the tree\n", argv[i]);
		else
			printf("<%s> count is %d\n", argv[i], (*tpp)->count);
	}
	return(0);
}

// binary tree search returning a pointer to the pointer leading to a hit
struct nodes **search(struct nodes **tpp, char *w) {
	/***** Need code here to search the binary tree***/
	

return(tpp);
}

void statistics(struct nodes *tp) {
	/***Need recursive code that will get all of the statistics *****/





}

#include <ctype.h>
/* Leave this, as it's from a previous program that I used*/
int get_word(char *s) {
	int c;
	do {
		c = getchar();
		if(c == EOF)
			return(0);
	} while(!isalpha(c) && !isdigit(c));
	do {
		if(isupper(c))
			c = tolower(c);
		*s++ = c;
		c = getchar();
	} while(isalpha(c) || isdigit(c));
	*s = 0;
	return(1);
}

Clarification of Question by james05-ga on 10 Oct 2005 07:17 PDT
Please note that the deadline for this is Thursday 10/13.  After that,
any solutions will not be required or paid for, as I will have help
elsewhere.

Thank you.
Answer  
There is no answer at this time.

Comments  
There are no comments at this time.

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy