using more than 1 client file

Basically I need to make my own priority queue so I have a .C and Header here for constructing the process table. Then another .C and header for the binary Tree

Everything compiles fine and runs fine on their own client file, but I want to know how to make a client file that is able to get the Element from my table and put them in my priority queue which is a Binary Tree.

table.h
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
//File for the list of PCB elements
#include <string>
using std::string;

struct table1{
  int entry, priority;
  string name, state;

};

int const MAX =20;

class pcb_table
{
 private:
  table1 table[MAX];
  int count;    
 public:
  pcb_table();
  ~pcb_table();
  void namesPriority();
  //void set_strings(string, string);
  void displayTable();


};


table.C generates a list of processes that are set to a random priority level and gives them a name
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
//fucntions
#include "PCBtable.h"
#include <string>
#include <iostream>
#include <ctime>
using namespace std;

pcb_table::pcb_table()
{
  count =20;
  int  entryValue =1;
  for (int i=0; i<=MAX-1; i++)
    {
      table[i].priority =0;
      table[i].entry= entryValue;
      table[i].name = " "; 
      table[i].state = "NEW ";
      entryValue++;
    }
}
pcb_table::~pcb_table()
{
}
/*void pcb_table::set_ints()
{

}
void pcb_table::set_strings()
{

}*/

void pcb_table::displayTable()
{
  for (int i=0; i<=count-1;i++)
    {
      cout << endl;
      cout << table[i].entry << " ";
      cout << table[i].name << " ";
      cout << table[i].priority << " ";
      cout << table[i].state << " ";
    }
  cout <<endl;
}
void pcb_table::namesPriority()
{
  srand(time(0));
  int num=1;
  
  for(int i=0;i<=MAX-1;i++)
    {
      num = rand()%50;
      table[i].priority = num;
    }
  table[1].name = "explorer.exe ";
  table[2].name = "firefox.exe ";
  table[3].name = "putty.exe ";
  table[4].name = "notepad.exe ";
  table[5].name = "wordpad.exe ";
  table[6].name = "minesweeper.exe ";
  table[7].name = "taskmgr.exe ";
  table[8].name = "winlogon.exe ";
  table[9].name = "nvvsvc.exe ";
  table[10].name = "LWEMon.exe ";
  table[11].name = "Java.exe ";
  table[12].name = "taskhost.exe ";
  table[13].name = "jusched.exe ";
  table[14].name = "dwm.exe ";
  table[15].name = "avgnt.exe ";
  table[16].name = "iexplore.exe ";
  table[17].name = "p1.exe ";
  table[18].name = "p2.exe ";
  table[19].name = "other1.exe ";
  table[0].name = "other2.exe ";
}

ReadyQ.h
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
//this will be the header file for the readyqueue
//#include "PCBtable.h"
#include <string>
using std::string;

typedef int elem_t;
typedef string elem_s;

struct Vertex{
  Vertex *Left;
  elem_t Elem;
  elem_s proc;
  Vertex *Right;
};

class BST
{
 private:
  Vertex *Root;
 public:
  BST();
  ~BST();
  void displayQueue();
  void INorderTraversal(Vertex*);
  void size();
  void insertProc(elem_t, elem_s);
  void removeHighestProc(elem_t, elem_s);
  void removeHighest(Vertex*, Vertex*);
};

ReadyQ.C a binary tree that has the processes from greatest priority to least
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
#include <iostream>
#include <string>
#include "ReadyQ.h"
using std::string;
using namespace std;

BST::BST()
{
  Root = NULL;
}

BST::~BST()
{

}

void BST::insertProc(elem_t T, elem_s S)
{
  Vertex *N;
  N= new Vertex;
  N->Left = NULL;
  N->Right = NULL;
  N->Elem = T;//integer priority element
  N->proc = S;//process name

  cout << "Trying to insert " << S << "   " << T << endl;
  if (Root ==NULL)
    {
      Root =N;
      cout << "adding " << S << " " << T << " as the root"<<endl;
    }
  else{//If a Root already exits
    Vertex *V;
    Vertex *Parent;
    V=Root;
    while (V!=NULL){//go down tree untill cant any further
      if ((N->Elem == V->Elem)||(N->Elem > V->Elem)){
	cout << " going to the left"<<endl;
	Parent =V;
	V=V->Left;
      }
      else if (N->Elem < V->Elem){
	cout << " going to the right" <<endl;
	Parent =V;
	V=V->Right;
      }
    }
    if (N->Elem > Parent->Elem){
      Parent->Left =N;
      cout<< " adding "<< S << " and " << T<< "as the left child of " << Parent->Elem<< endl;
    }
    else {
      Parent->Right =N;
      cout<< " adding " << S << " and "<< T << "as the right child of " << Parent->Elem <<endl;
    }
  }
}

void BST::removeHighestProc(elem_t T, elem_s S)
{
  cout << "Tring to delete " << T << " " << S << endl;
  Vertex *V;
  Vertex *Parent = NULL;
  if ((T == Root->Elem)&&(Root->Left==NULL)&&(Root->Right ==NULL))
    { cout << " deleting the lonely root" << endl;
      delete Root;
      Root = NULL;
      return;}
  V = Root;
  while (V!=NULL)
    {
      if (T==V->Elem)//found it
	{ cout<< " ...removing " << V->proc << endl;
	  removeHighest(V,Parent);
	  return;
	}
      else if (T > V->Elem)
	{ Parent = V;
	  V=V->Left;
	}
      else{
	Parent =V;
	V=V->Right;
      }
    }
  cout << "Did not find that process" <<endl;
}

void BST::removeHighest(Vertex *V, Vertex *P)
{
  if ((V->Left == NULL) && (V->Right ==NULL))
    {
      if (V== P->Left)
	{
	  delete V;
	  P->Left = NULL;
	}
      else
	{
	  delete V;
	  P->Right =NULL;
	}
    }
  
  else if (( V->Right ==NULL) &&(V->Left!=NULL))
    {
      if (P->Left ==V)
	{
	  P->Left = V->Left;
	  delete V;
	}
      else
	{
	  P->Right = V->Left;
	  delete V;
	}
    }
  else if ((V->Left==NULL)&&(V->Right!=NULL))	  
    {	   
      P->Left=V;
      delete V;
    }
}
void BST::size()
{
}

void BST::displayQueue()
{
  cout << "The queue currently is: " << endl;
  INorderTraversal(Root);
}
void BST::INorderTraversal(Vertex* V)
{
  if (V!=NULL)
    {
      INorderTraversal (V->Left);
      cout << V->proc << V->Elem<<endl;
      INorderTraversal(V->Right);
    }
}

my coding in my files should all be fine, plan to comment when finished
Topic archived. No new replies allowed.