Click here to Skip to main content
15,912,897 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
Generalperformance question Pin
Gary Kirkham19-Sep-03 10:59
Gary Kirkham19-Sep-03 10:59 
GeneralRe: performance question Pin
Joe Woodbury19-Sep-03 12:35
professionalJoe Woodbury19-Sep-03 12:35 
GeneralRe: performance question Pin
Tim Smith19-Sep-03 12:40
Tim Smith19-Sep-03 12:40 
GeneralRe: performance question Pin
Gary Kirkham19-Sep-03 13:26
Gary Kirkham19-Sep-03 13:26 
GeneralRe: performance question Pin
Gary R. Wheeler20-Sep-03 3:28
Gary R. Wheeler20-Sep-03 3:28 
GeneralRe: performance question Pin
Gary Kirkham20-Sep-03 11:52
Gary Kirkham20-Sep-03 11:52 
GeneralRe: performance question Pin
Gary R. Wheeler20-Sep-03 14:13
Gary R. Wheeler20-Sep-03 14:13 
Generalpassing data structures Pin
Sirrius19-Sep-03 10:36
Sirrius19-Sep-03 10:36 
I need to traverse the tree with the output function and send its data or the tree over to the List class to be inserted into a List. I am having problems implementing the arguments to be passed in the functions treeNode::Output and List::insertNode. Can somebody give me some ideas. Thanks.

Here is my code:
#include <iostream>
#include <string>
#include "List.h"

using namespace std;






class treeNode
{

string name;
treeNode *smaller, *bigger;

public:


treeNode(string newName="", treeNode *newSmaller=NULL, treeNode *newBigger=NULL)
{
name=newName;
smaller=newSmaller;
bigger=newBigger;
}

void add(string newName)
{
if(newName<name)
{
if(smaller==NULL)
smaller=new treeNode(newName);
else
smaller->add(newName);
}
if(newName>name)
{
if(bigger==NULL)
bigger=new treeNode(newName);
else
bigger->add(newName);
}
}


void output(List &l)
{
if(smaller!=NULL)
smaller->output(l);


l.insertNode();

if(bigger!=NULL)
bigger->output(l);
}



};



void main()
{

List l;
treeNode t;
string newName;
int howMany;

cin >> howMany;

for(int i=0; i<howMany; ++i)
{
cin >> newName;
t.add(newName);
//l.insertNode(treeNode *t);
}

t.output(l);
//l.outputList(cout);
}


#include <iostream>
#include <string>

#ifndef LIST_H
#define LIST_H

using namespace std;

struct node
{
string data;
node *next;
};




//Linked List class
class List
{
node *first;
public:

List()
{
first=NULL;
}
void insertNode()
{
node *p;
cout << newName << endl;
p=new node;
p->data=newName;
p->next=first;
first=p;

}


void outputList(ostream &out)
{

node *p;
p=first;

if(!empty())
{

while(p!=NULL)
{
cout << p->data << endl;
p=p->next;
}
}
else
cout << "The list is empty!" << endl;
}

bool empty()
{
if(first==NULL)
return true;
else
return false;
}


};

#endif



GeneralRe: passing data structures Pin
Michael Dunn19-Sep-03 11:11
sitebuilderMichael Dunn19-Sep-03 11:11 
GeneralRe: passing data structures Pin
Sirrius19-Sep-03 14:36
Sirrius19-Sep-03 14:36 
GeneralRe: passing data structures Pin
Sirrius19-Sep-03 13:00
Sirrius19-Sep-03 13:00 
GeneralWord wrap in Rich Edit and multiline edit Pin
insanely42019-Sep-03 9:07
insanely42019-Sep-03 9:07 
GeneralRe: Word wrap in Rich Edit and multiline edit Pin
David Pritchard1-Jun-04 14:21
David Pritchard1-Jun-04 14:21 
GeneralFinding the sum of all intergers between x &amp; y Pin
pam128819-Sep-03 9:03
pam128819-Sep-03 9:03 
GeneralRe: Finding the sum of all intergers between x &amp; y Pin
Tim Deveaux19-Sep-03 9:31
Tim Deveaux19-Sep-03 9:31 
GeneralRe: Finding the sum of all intergers between x &amp; y Pin
Tim Smith19-Sep-03 9:34
Tim Smith19-Sep-03 9:34 
GeneralRe: Finding the sum of all intergers between x &amp; y Pin
Tim Smith19-Sep-03 9:34
Tim Smith19-Sep-03 9:34 
GeneralRe: Finding the sum of all intergers between x &amp; y Pin
Harco19-Sep-03 9:40
Harco19-Sep-03 9:40 
Generalinhereted static member referencing Pin
Harco19-Sep-03 8:58
Harco19-Sep-03 8:58 
GeneralRe: inhereted static member referencing Pin
antlers19-Sep-03 12:07
antlers19-Sep-03 12:07 
GeneralExport CWnd* from DLL Pin
Mathias S.19-Sep-03 8:26
Mathias S.19-Sep-03 8:26 
GeneralMessages to derived CWnd object on CFormView Pin
Anonymous19-Sep-03 8:23
Anonymous19-Sep-03 8:23 
GeneralOnPaint() as opposed to OnDraw() Pin
ComboController19-Sep-03 8:14
ComboController19-Sep-03 8:14 
GeneralRe: OnPaint() as opposed to OnDraw() Pin
David Crow19-Sep-03 8:30
David Crow19-Sep-03 8:30 
GeneralDropDown Combo box background color issue Pin
sanjay zore19-Sep-03 6:49
sanjay zore19-Sep-03 6:49 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.