Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C++ Moderated > Re: Filestream ...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 5 of 7 Topic 9506 of 10094
Post > Topic >>

Re: Filestream problems

by Hani Sharabash <HaniBash@[EMAIL PROTECTED] > Apr 17, 2008 at 04:20 PM

On Apr 17, 3:59 am, Ulrich Eckhardt <eckha...@[EMAIL PROTECTED]
> wrote:
> Hani Sharabash wrote:
> > #include "binarytree.h"
> > #include "treenode.h"
> > #include "datanode.h"
>
> I read your code and I'm pretty sure the problem is in these files
> somewhere. Please provide a minimal but complete example, i.e. one that
> doesn't contain any unnecessary stuff but still contains everything that
> one needs to reproduce the problem.
>
> Uli
>
> --
> Sator Laser GmbH
> Geschäftsführer: Michael Wöhrmann, Amtsgericht Hamburg HR B62 932
>
>       [ Seehttp://www.gotw.ca/resources/clcm.htmfor
info about ]
>       [ comp.lang.c++.moderated.    First time posters: Do this! ]

Here are the contents of binarytree.cpp.

#include "binarytree.h"


BinaryTree::BinaryTree()
{
	root = NULL;
}

void BinaryTree::insert(string s)
{
      Treenode* newnode = new Treenode(s);
      root = recursiveInsert(root, newnode);
}

Treenode* BinaryTree::recursiveInsert(Treenode* subroot, Treenode*
newnode)
{
      if (subroot == NULL)
           return newnode;
      else if (newnode->getWord() < subroot->getWord())
           subroot->left = recursiveInsert(subroot->left, newnode);
      else if (newnode->getWord() > subroot->getWord())
           subroot->right = recursiveInsert(subroot->right, newnode);
      else
           subroot->increaseWordCount();
      return subroot;
}

void BinaryTree::walk()
{
      if (root == NULL)
         cout << "Empty Tree";
      else
          recursiveWalk(root);

      cout << endl;
}


void BinaryTree::recursiveWalk(Treenode* subroot)
{
      if (subroot == NULL)
         return;
      recursiveWalk(subroot->left);
      cout << subroot->getWord() << " ";
      recursiveWalk(subroot->right);

}

binarytree.h:
#ifndef BINARYTREE_H
#define BINARYTREE_H

#include "treenode.h"

using namespace std;

class Treenode;

class BinaryTree
{

public:
	BinaryTree();

	void insert(string s);
	Treenode* recursiveInsert(Treenode* subroot, Treenode* newnode);

	void walk();
	void recursiveWalk(Treenode* subroot);


private:
    	Treenode* root;



};

#endif



treenode.cpp:

#include "treenode.h"


Treenode::Treenode(string s)
{
	data->word = s;
	data->wordCount = 1;
	left = right = NULL;
}

string Treenode::getWord()
{
	return data->word;
}

int Treenode::getWordCount()
{
     return data->wordCount;
}

void Treenode::increaseWordCount()
{
      data->wordCount++;
}


treenode.h:

#ifndef TREENODE_H
#define TREENODE_H

#include <iostream>

#include "binarytree.h"
#include "datanode.h"

using namespace std;

class Treenode
{
friend class BinaryTree;

public:
     Treenode(string s);

     string getWord();
     int getWordCount();
     void increaseWordCount();

private:
     Datanode* data;
     Treenode *left, *right;
};

#endif

datanode.h (there is no datanode.cpp file):

#ifndef DATANODE_H
#define DATANODE_H


using namespace std;

class Datanode
{
friend class Treenode;

private:
      string word;
      int wordCount;
};

#endif

Thank you so much for your help.


On Apr 17, 3:56 am, Carl Barron <cbarron...@[EMAIL PROTECTED]
> wrote:
> In article
> <73c37290-e418-4d12-934a-c33075210...@[EMAIL PROTECTED]
>,
>
> Hani Sharabash <HaniB...@[EMAIL PROTECTED]
> wrote:
> > I'm writing a program in which I read text from a file, store all of
> > the words into a binary search tree, and then print the words out to
> > the screen in order from that tree.
>
> > For some reason, opening and using an input filestream is causing
> > problems for my binary tree functions. When I try to use them
> > together, my program crashes at runtime. For example:
> > \
>
>     first I would make sure where the error is in this case I would
> imput the data and store it in a stanard sorted assoc. container
> say std::set<std::string> and print the results from
> std::set<std::string> before I blame <fstream>  probably there is
> a bug in your binary tree code. But if reading it into an
> std::set<string> works then its not <fstream>.
>

I don't understand. Could you clarify a little more?


-- 
      [ See http://www.gotw.ca/resources/clcm.htm
for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]
 




 7 Posts in Topic:
Filestream problems
Hani Sharabash <HaniBa  2008-04-16 11:38:04 
Re: Filestream problems
Michael.Boehnisch@[EMAIL   2008-04-17 03:49:28 
Re: Filestream problems
Ulrich Eckhardt <eckha  2008-04-17 03:59:44 
Re: Filestream problems
Carl Barron <cbarron41  2008-04-17 03:56:36 
Re: Filestream problems
Hani Sharabash <HaniBa  2008-04-17 16:20:31 
Re: Filestream problems
Carl Barron <cbarron41  2008-04-17 19:35:45 
Re: Filestream problems
"Thomas J. Gritzan&q  2008-04-17 19:34:04 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sat Oct 11 8:04:58 CDT 2008.