Aug 23, 2008 at 10:17pm UTC
Can any one help to define ??? part in my data structure project?
thanks.
....
...
struct Customer{
int tckimlikno; // customer identity number
string name;
string surname;
void set(int a, string b, string c);
};
struct customerNode
{
Customer person;
customerNode * next, *prev;
customerNode():next(NULL),prev(NULL){};
};
class activity
{
int actNo,size;
string actName;
customerNode *headc,*tailc;
customerNode * searchID(int);
public:
activity(int a , string b);
activity();
int getAct() { return actNo; };
string getName() { return actName; };
int getSize() { return size; };
void add(Customer & C);
void deleteCustomer(int);
void print() const;
};
activity::activity()
{
headc = NULL;
tailc = NULL,
size = 0;
actNo = 0;
actName = "";
}
activity::activity(int a , string b)
{
headc=NULL;
tailc = NULL;
size = 0;
actNo = a;
actName = b;
}
class Tree{
public:
struct treeNode{
activity element;
treeNode *left,*right;
treeNode():left(NULL),right(NULL){};
};
Tree():root(NULL),treesize(0){};
treeNode * nodeSearch(int acno, string actname, treeNode * node);
treeNode * getRoot() { return root; };
void addAct(activity & dep);
void removeAct(int acno, string actname);
int deleteTree(treeNode *treep);
private:
treeNode *root;
int treesize;
};
void Customer::set(int a, string b, string c)
{
tckimlikno = a; name = b; surname = c;
};
customerNode * activity::searchID(int _id)
{
????????????????????????????????????????????
}
void activity::add(Customer &C)
{
-
}
void activity::deleteCustomer(int id)
{
-
}
void activity::print() const
{
-
};
Tree::treeNode * Tree::nodeSearch(int acno, string actname,Tree::treeNode *node)
{
-
}
int Tree::deleteTree(Tree::treeNode *treep)
{
-
}
void Tree::removeAct(int acno, string actname)
{
-}
}
void Tree::addAct(activity &act)
{
???????????????????????*
}
void menu()
{
cout << "MENU" << endl;
cout << "1- Add a activity" << endl;
}
int main()
{
....
case 1:
{
int a;
string b;
cout << "Enter new activity name: ";
cin >> b;
cout << "Enter the activity code: ";
cin >> a;
activity newAct(a,b);
menucontent.addAct(newAct);
break;
}
....
}
return 0;
}
Last edited on Aug 23, 2008 at 11:15pm UTC
Aug 23, 2008 at 10:35pm UTC
If the order in the activity list doesn't matter, then you have the choice of adding it to the start or end of the list - doesn't really matter much which you choose.
Basically you need to (assuming we put it at the end):
1- Create a customer node that stores the given customer
2 - Point the new node's previous pointer to the end of the list
3 - Point the next pointer of the last node in the list to the new node (make sure to check for NULL so you don't do this if the list is empty)
4 - Point the end of the list to the new node
5 - Point the next pointer of the new node to NULL