hi
I'm new to c++,I really need your help :(
I have an assignment that it's title is a latin sort.It needs to read from the text file and then sort the words by bst and again write the sorted files to a text file,I also attach the assignment
I can read from the file and I think by using getline(in,this.s0,',') we can read delimetered words.but i dont know how to insert the words to the bst for iorder traversal.how to pass the words one by one for inserting in the bst.
and to write the words into a text file.this is my code.with lots of mistakes :),would you please help me with this?
thanks
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <assert.h>
#include <string.h>
#include "stdafx.h"
#include "cstdlib"
#include "stdio.h"
#include "conio.h"
#include "iostream"
#include "fstream"
#include "stdlib.h"
#include "math.h"
#include <iostream>
#include <iomanip>
#include <fstream>
#include <iostream>
#include <string>
#include <fstream>
#include <iostream>
#include <sstream>
#include<iostream>
#include <sstream>
#include <string>
#include <vector>
#include <fstream>
#include <string>
#include <vector>
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
//======================
struct words
{
string s0;
string s1;
string s2;
string s3;
string s4;
};
//=======================
class BSTree
{
private:
struct treeNode
{
treeNode* left;
treeNode* right;
string word;
treeNode(string s)
{
word = s;
left = NULL;
right = NULL;
}
};
public:
treeNode* root;
BSTree()
{
root = NULL;
}
void insert(treeNode *&root, string newNode)
{
if(root == NULL)
{
root = new treeNode(newNode);
return;
}
else if(newNode < root->word)
{
insert(root->left, newNode);
}
else
{
insert(root->right, newNode);
}
}
void print(treeNode *node)
{
if(node != NULL)
{
print(node->left);
cout << node->word << endl;
print(node->right);
}
}
};
int main()
{
while(1)
{
ifstream fis;
BSTree bst;
fis.open("E:\example.txt");
while(!fis.eof())
{
//=================
vector<words> wordList;
words thisWord;
while( getline(fis,thisWord.s0,':') )
{
getline(fis,thisWord.s1,',');
getline(fis,thisWord.s2,',');
getline(fis,thisWord.s3);
//getline(in,pp.s4);
wordList.push_back(thisWord);
}
// // now just display all the data in the vector
vector<words>::iterator it = wordList.begin();
for(; it != wordList.end(); it++)
{
string word;
thisWord.word = word;
wordList.push_back(thisWord);
//cout << (*it).s0 << ":" << (*it).s1 << "," << (*it).s2 << "," << (*it).s3 /*<< (*it).s4 */<< "\n";
//cout << (*it).s0 << ":" <<arr1 << "," << arr2 << "," << arr3 << "\n";
}
}
//fis >> str;
//--------------------------------------
while( getline(fis,thisWord.s0,'\n') )
{
getline(fis,thisWord.s1,':');
getline(fis,thisWord.s1,',');
getline(fis,thisWord.s2,',');
getline(fis,thisWord.s3);
//getline(fis,thisWord.s4);
wordList.push_back(thisWord);
string word1, word2,word3 ;
//thisWord.word = word;
word1=thisWord.s1;
word2=thisWord.s2;
word3=thisWord.s3;
cout << word1<<"---"<<word2<<"---"<<"\n";
}
string word;
bst.insert(bst.root,word);
}
bst.print(bst.root);
}
}