1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217
|
#ifndef DICTIONARY_H
#define DICTIONARY_H
#include <QMainWindow>
#include <QCloseEvent>
#include <tree.h>
using namespace std;
namespace Ui {
class Dictionary;
}
class Dictionary : public QMainWindow
{
Q_OBJECT
public:
explicit Dictionary(QWidget *parent = 0);
~Dictionary();
Tree *t;
private:
Ui::Dictionary *ui;
private slots:
};
#endif // DICTIONARY_H
--------------------------- GUI Dictionary cpp file
#include "dictionary.h"
#include "ui_dictionary.h"
#include <QFile>
#include <QFileDialog>
#include <QTextStream>
#include <QMessageBox>
#include <QtGlobal>
using namespace std;
Dictionary::Dictionary(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::Dictionary)
{
ui->setupUi(this);
t = new Tree(this);
connect(ui->actionO_pen, SIGNAL(triggered()), this, SLOT(fileOpen()));
connect(ui->actionE_xit, SIGNAL(triggered()), this, SLOT(close()));
connect(ui->keyboardword, SIGNAL(triggered()), t, SLOT(add(NodePtr&,QString)));
connect(ui->actionA_scending_order, SIGNAL(triggered()), t, SLOT(disp_inord(NodePtr)));
connect(ui->actionD_escending_order, SIGNAL(triggered()), t, SLOT(disp_inreverse(NodePtr)));
}
void Dictionary::fileOpen()
{
}
void Dictionary::closeEvent(QCloseEvent *event)
{
}
bool Dictionary::canClose()
{
}
Dictionary::~Dictionary()
{
delete ui;
}
------------------------------TREE header file
#ifndef TREE_H
#define TREE_H
#include <QMainWindow>
#include <QObject>
#include <QWidget>
using namespace std;
struct tree_node { //Create Node "template".
tree_node *left; // left subtree has smaller elements
tree_node *right; // right subtree has larger elements
QString word; // This tree stores int values
unsigned int count = 0; //Count for duplicates.
};
typedef tree_node* NodePtr;
class Tree : public QObject
{
Q_OBJECT
private:
NodePtr fRoot; //Create Root of Binary Tree
int size;
public:
explicit Tree(QObject *parent = 0);
~Tree();
NodePtr &getRoot() { return fRoot; }
void removeNode (NodePtr &ptr);
public slots:
void addverbose(NodePtr &ptr, QString aword);
void addsilent(NodePtr &ptr, QString aword);
void disp_inord(NodePtr ptr);
void disp_inreverse(NodePtr ptr);
};
#endif // TREE_H
-------------------------------------------------Tree cpp file
#include "tree.h"
#include <iostream>
#include <QString>
using namespace std;
Tree::Tree(QObject *parent) : QObject(parent)
{
fRoot = NULL; // Initialize pointer (make root node to point to Null).
}
Tree::~Tree()
{
removeNode(fRoot);
}
void Tree::disp_inord(NodePtr ptr) //Display contents of dictionary
{
if (ptr != NULL)
{
disp_inord(ptr->left); // print left subtree
std::cout << qPrintable(ptr->word) << '\n'; // print this node
disp_inord(ptr->right); // print right subtree
}
}
void Tree::disp_inreverse(NodePtr ptr) //Display contents of dictionary in reverse order
{
if (ptr != NULL)
{
disp_inreverse(ptr->right); // print right subtree
std::cout << qPrintable(ptr->word) << '\n'; // print this node
disp_inreverse(ptr->left); // print left subtree
}
}
/*auto new_end = std::remove_if(s.begin(), s.end(), [](QChar c) { return c.isPunct(); });
s.resize(new_end - s.begin()); CODE TO REMOVE CHARACTERS WHICH AREN'T LETTERS OR NUMBERS.*/
void Tree::addverbose(NodePtr &ptr, QString aword){ //Why ptr passed as a reference here ????????????????????????????????????????
}
void Tree::addsilent(NodePtr &ptr, QString aword){ //Why ptr passed as a reference here ????????????????????????????????????????
}
void Tree::removeNode(NodePtr &ptr){
if(ptr != NULL)
{
removeNode (ptr->left);
removeNode (ptr->right);
delete ptr;
}
}
|