Skip to content

Commit 4b5f325

Browse files
committed
second commit
2 parents dab7d0e + dccbebb commit 4b5f325

File tree

10 files changed

+441
-46
lines changed

10 files changed

+441
-46
lines changed

Faculty.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ void Faculty::setID(unsigned int ID)
3434
IDnum = ID;
3535
}
3636

37+
void Faculty::addtolist(unsigned int aID)
38+
{
39+
adviseeIDs -> addBack (aID);
40+
}
41+
3742
void Faculty::printinfo()
3843
{
3944
cout << endl << "Id: " << IDnum << endl <<
@@ -56,6 +61,24 @@ int Faculty::listsize()
5661
return adviseeIDs -> size();
5762
}
5863

64+
unsigned int Faculty::removeadID(unsigned int& sID)
65+
{
66+
if (adviseeIDs -> isEmpty() == true) {
67+
cout << "There are no advisees under this faculty" << endl;
68+
return sID = 0;
69+
}
70+
else {
71+
if (adviseeIDs -> contains (sID) == false) {
72+
cout << "This advisee is not present under this faculty" << endl;
73+
return sID = 0;
74+
}
75+
else {
76+
adviseeIDs -> remove (sID);
77+
return sID;
78+
}
79+
}
80+
}
81+
5982
bool operator== (const Faculty &f1, const Faculty &f2) {
6083
return (f1.IDnum == f2.IDnum);
6184
}

Faculty.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ class Faculty : public Person {
1212
void printinfo();
1313
void printexit();
1414
int listsize();
15+
unsigned int removeadID(unsigned int& sID);
16+
void addtolist(unsigned int aID);
1517

1618
friend bool operator== (const Faculty &f1, const Faculty &f2);
1719
friend bool operator!= (const Faculty &f1, const Faculty &f2);

GenBST.h

Lines changed: 118 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,17 @@ class BST {
2626

2727
void individualInfo(T k);
2828
unsigned int facultyInfo(T k);
29+
unsigned int changeFadvisor (T k, unsigned int& afID);
30+
unsigned int removeSadvisee (T k, unsigned int& asID);
31+
bool checkAdvisor (T k, unsigned int afID);
32+
void addFadvisee (T k, unsigned int asID);
33+
T getobject(T& k);
34+
void adviseeInfo (unsigned int fID);
2935

3036
TreeNode<T> *getSuccessor (TreeNode<T> *d);
3137

3238
private:
39+
unsigned int fID;
3340
TreeNode<T> *root;
3441
friend class Simulation;
3542
};
@@ -324,8 +331,102 @@ unsigned int BST<T>::facultyInfo (T k)
324331
return current -> key.getAdvisorID();
325332
}
326333

327-
/*template <class T>
328-
unsigned int BST<T>::adviseeInfo (T k)
334+
template <class T>
335+
unsigned int BST<T>::changeFadvisor (T k, unsigned int& afID)
336+
{
337+
TreeNode<T> *parent = root;
338+
TreeNode<T> *current = root;
339+
340+
//now we need to find it
341+
while (current -> key != k) {
342+
if (k < current -> key) {
343+
parent = current;
344+
current = current -> left;
345+
}
346+
else { //go right
347+
parent = current;
348+
current = current -> right;
349+
}
350+
}
351+
fID = current -> key.getAdvisorID();
352+
current -> key.setAdvisorID(afID);
353+
return fID;
354+
}
355+
356+
template <class T>
357+
unsigned int BST<T>::removeSadvisee (T k, unsigned int& asID)
358+
{
359+
TreeNode<T> *parent = root;
360+
TreeNode<T> *current = root;
361+
362+
//now we need to find it
363+
while (current -> key != k) {
364+
if (k < current -> key) {
365+
parent = current;
366+
current = current -> left;
367+
}
368+
else { //go right
369+
parent = current;
370+
current = current -> right;
371+
}
372+
}
373+
if (current -> key.removeadID (asID) == 0) {
374+
return asID = 0;
375+
}
376+
else {
377+
return asID;
378+
}
379+
}
380+
381+
template <class T>
382+
bool BST<T>::checkAdvisor (T k, unsigned int afID)
383+
{
384+
TreeNode<T> *parent = root;
385+
TreeNode<T> *current = root;
386+
387+
//now we need to find it
388+
while (current -> key != k) {
389+
if (k < current -> key) {
390+
parent = current;
391+
current = current -> left;
392+
}
393+
else { //go right
394+
parent = current;
395+
current = current -> right;
396+
}
397+
if (current == NULL)
398+
return false;
399+
}
400+
if (current -> key.getAdvisorID () == afID) {
401+
return true;
402+
}
403+
else {
404+
return false;
405+
}
406+
}
407+
408+
template <class T>
409+
void BST<T>::addFadvisee(T k, unsigned int asID)
410+
{
411+
TreeNode<T> *parent = root;
412+
TreeNode<T> *current = root;
413+
414+
//now we need to find it
415+
while (current -> key != k) {
416+
if (k < current -> key) {
417+
parent = current;
418+
current = current -> left;
419+
}
420+
else { //go right
421+
parent = current;
422+
current = current -> right;
423+
}
424+
}
425+
current -> key.addtolist(asID);
426+
}
427+
428+
template <class T>
429+
T BST<T>::getobject(T& k)
329430
{
330431
TreeNode<T> *parent = root;
331432
TreeNode<T> *current = root;
@@ -341,5 +442,18 @@ unsigned int BST<T>::adviseeInfo (T k)
341442
current = current -> right;
342443
}
343444
}
344-
current -> key.listsize();
345-
}*/
445+
return current -> key;
446+
}
447+
448+
template <class T>
449+
void BST<T>::adviseeInfo (unsigned int fID)
450+
{
451+
TreeNode<T>* node = root;
452+
if (node == NULL)
453+
return;
454+
455+
recPrintAll (node -> left);
456+
if (node -> key.getAdvisorID() == fID)
457+
node -> key.printinfo();
458+
recPrintAll (node -> right);
459+
}

GenDlinkedlist.h

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ class GenDlinkedlist {
2222
void reduce ();
2323
T sort (T c, T d, T& s, T& med);
2424
int size();
25+
unsigned int listDetails();
2526

2627
private:
2728
friend class Faculty;
@@ -129,9 +130,9 @@ GenNode<T> *GenDlinkedlist<T>::remove (T key)
129130
node = node -> next;
130131
}
131132

132-
if (node == trailer) {
133-
cout << "There is no node with element " << key << " in the linked list." << endl;
134-
}
133+
//if (node == trailer) {
134+
//cout << "There is no node with element " << key << " in the linked list." << endl;
135+
//}
135136
}
136137
}
137138

@@ -176,6 +177,20 @@ void GenDlinkedlist<T>::printList() const
176177
}
177178
}
178179

180+
template <class T>
181+
unsigned int GenDlinkedlist<T>::listDetails()
182+
{
183+
GenNode<T> *curr = new GenNode<T>;
184+
curr = header;
185+
curr = curr -> next;
186+
187+
while (curr != trailer) {
188+
return curr -> elem;
189+
curr = curr -> next;
190+
}
191+
}
192+
193+
179194
template <class T>
180195
int GenDlinkedlist<T>::size()
181196
{

Genstack.h

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
#include <iostream>
2+
3+
using namespace std;
4+
5+
template <class T>
6+
class GenStack {
7+
T *genArray;
8+
int capacity, t;
9+
friend class Simulation;
10+
11+
public:
12+
int size() const; //const because they do not alter the contents of the stack
13+
bool empty() const;
14+
const T& top ();
15+
void pop ();
16+
void push (const T& p);
17+
18+
GenStack();
19+
~GenStack();
20+
};
21+
22+
template <class T>
23+
GenStack<T>::GenStack()
24+
{
25+
capacity = 5;
26+
genArray = new T [capacity];
27+
t = -1;
28+
}
29+
30+
template <class T>
31+
GenStack<T>::~GenStack()
32+
{
33+
delete genArray;
34+
}
35+
36+
template <class T>
37+
int GenStack<T>::size() const
38+
{
39+
return (t+1);
40+
}
41+
42+
template <class T>
43+
bool GenStack<T>::empty() const
44+
{
45+
return (t<0);
46+
}
47+
48+
template <class T>
49+
const T& GenStack<T>::top()
50+
{
51+
return genArray[t];
52+
}
53+
54+
template <class T>
55+
void GenStack<T>::pop()
56+
{
57+
if (empty()) {
58+
cout << "There are no elements in the stack to pop!!" << endl;
59+
exit(1);
60+
}
61+
else {
62+
--t;
63+
}
64+
}
65+
66+
/*template <class T>
67+
T GenStack <T>::top()
68+
{
69+
if (empty()) {
70+
cout << "There are no elements in the stack" << endl;
71+
exit(1);
72+
}
73+
else {
74+
return genArray[t];
75+
}
76+
}
77+
78+
template <class T>
79+
T GenStack <T>::pop()
80+
{
81+
if (empty()) {
82+
cout << "There are no elements in the stack" << endl;
83+
exit(1);
84+
}
85+
else {
86+
return genArray[t--];
87+
}
88+
}*/
89+
90+
template <class T>
91+
void GenStack<T>::push (const T& p)
92+
{
93+
if (size() == capacity) {
94+
pop();
95+
genArray[++t] = p;
96+
}
97+
else {
98+
genArray[++t] = p;
99+
}
100+
}

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
# Assignment5
2+
3+
I worked with Brandon Fabre for this assignment.

0 commit comments

Comments
 (0)