Hey All I am having issues with my code and it has something to do with the way my double linked list is working.
I cant figure out if its not setting the m_prev pointer if at all and what is going on with my m_next pointer. Any help would be greatly appreciated I have been banging my head on the desk for the last 7 hours working on it. I just need to get the pointers working correctly and I think that it will be working correctly.
Just a little bit of background this is a homework project I am working on that is suppose to simulate a operating system scheduler. The main contains a variable that gets used over and over again during input so its contents are always overwritten after the while loop restarts. it is called process. I want to insert into the Startup queue and I thought I had it until I did some cout statements to see what was going on.
Thanks In advanced!!
Here is the complete code:
//***********************************
// include files
//***********************************
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cctype>
#include <cstdlib>
#include <cmath>
using namespace std;
typedef unsigned char boolean;
//***********************************
// define directives
//***********************************
// Directive to store the minimum time slice
#define MIN_TIME_SLICE 10
// Directive to store the maximum time slice
#define MAX_TIME_SLICE 300
// Directive to store the lowest priority (*note* higher number = lower priority)
#define MIN_PRIORITY 140
// Directive to store the highest priority(*note* lower number = higher priority)
#define MAX_PRIORITY 100
// Directive to store the highest nice value(*note* lower number = nicer Process)
#define MAX_NICE = -20
// Directive to store the lowest nice value (*note* higher number = not so nice Process)
#define MIN_NICE = 19
//***********************************
// globals
//***********************************
// Clock for my scheduler
long myClock;
// Max amount of proccess in the file
int maxProcesses;
// Total turn around time for all Processes
long totalTAT;
// Total wait time for all Processes
long totalWT;
// Total CPU utiliation Time for all Processes
double totalCUT;
// The global count variables that gets used over and over again
int i, j, k;
// The global temp integer variable
int tempInt;
// class that defines what a Processes is
class ProcessContents{
public:
// constructors
ProcessContents( );
ProcessContents(ProcessContents*);
// values in a process
int pid; //pid of Process
int nice; // Processes nice value
int arrivalTime; // Processes arrival time
int numCPUBursts; // number of cpu bursts
int numIOBursts; // number of i/o bursts = #cpu bursts - 1
int totalBursts;
int endTime; // Processes end time
int priority; // priority of Process
int timeslice; // Processes timesliceSTRUCT AS A FUNCTION PARAMETER DECLARATION
int* burst; // dynamic array of cpu bursts and io bursts for the Process
void insert(ProcessContents*);
void setData(ProcessContents*);
// setters
ProcessContents* getPrev();
ProcessContents* getNext();
void setNext(ProcessContents*);
ProcessContents getData();
int getDataEl();
void reset();
void prev();
void next();
void end();
//Boolean
boolean isBeginning();
boolean isEnd();
boolean isEmpty();
private:
ProcessContents *m_next, *m_prev, *m_curr;
};
ProcessContents :: ProcessContents() {
m_prev = NULL;
m_next = NULL;
m_curr = this;
endTime = 0;
priority = 69;
timeslice = 143;
burst = NULL;
}
ProcessContents :: ProcessContents(ProcessContents* previous) {
m_prev = previous;
cout << " PRINT PREVIOUS " << previous << endl;
m_next = NULL;
priority = 96;
}
void ProcessContents::insert(ProcessContents* pNode) {
while (m_curr->getNext() != NULL)
m_curr = m_curr->getNext();
m_curr->setData(pNode);
cout << "POINTERS: "<< m_curr<< " " << m_next << " " << m_prev << endl;
m_curr->setNext(new ProcessContents(m_curr));
cout << "POINTERS AFTER: "<< m_curr<< " " << m_next << " " << m_prev << endl;
// creates the link between a newly created list and the current list
}
void ProcessContents::setData(ProcessContents* pNode) {
int z;
pid = pNode -> pid;
nice = pNode -> nice;
arrivalTime = pNode -> arrivalTime;
numCPUBursts = pNode -> numCPUBursts;
numIOBursts = pNode -> numIOBursts;
totalBursts = pNode -> totalBursts;
endTime = pNode -> endTime;
priority = pNode -> priority;
timeslice = pNode -> timeslice;
burst = new int[totalBursts];
for (z = totalBursts - 1; z >= 0; z--) {
burst[z] = pNode -> burst[z];
}
}
ProcessContents ProcessContents::getData() {
cout << "Pid: " << pid << endl;
cout << "Arrival time: " << arrivalTime << endl;
cout << "Priority: " << priority << endl;
cout << "Total Burst: " << totalBursts << endl;
}
ProcessContents* ProcessContents::getPrev() {
return m_prev;
}
ProcessContents* ProcessContents::getNext() {
return m_next;
}
void ProcessContents::setNext(ProcessContents* link) {
m_next = link;
}
void ProcessContents::reset() {
m_curr = this;
}
void ProcessContents::next() {
m_curr = m_curr->getNext();
}
void ProcessContents::prev() {
m_curr = m_curr->getPrev();
}
boolean ProcessContents::isEnd() {
return m_curr->getNext() == NULL ? 1 : 0;
}
boolean ProcessContents::isBeginning() {
return m_curr == NULL ? 1 : 0; ;
}
boolean ProcessContents::isEmpty() {
return m_curr->getNext() == m_curr->getPrev() ? 1 : 0;
}
/*
int Queue :: calculateDynPty(ProcessContents* node){
// have to adjust this part
node -> priority = (node -> priority) + (-1)*((node -> Bonus) + (node -> priority));
return (node -> priority);
}
double Queue :: calculateTimeSlice(ProcessContents *node){
node -> priority = (int)ceil((-180.0/49.0)*(double)(calculateDynPty(node))+(26900.0/49.0));
return (node -> priority);
}
*/
//***********************************
// function definitions
//***********************************
// Function that gets all the input from unix file redirection and places them into the startup queue
/*
// *****************MOST PRINT STATEMENTS*******************************
// function that prints Arrival Processes in the active queue
void printArrivalActive(Process myProcessIn);
// function that prints when a Process enters the cpu
void printEnterCPU(Process myProcessIn, int time);
// function that prints when a Process is preempted
void printPreempt(Process myProcessIn, Process myProcessOut, int time);
//function that prints when a Process is finsihed with all cpu bursts
void printFinishCPU(Process myProcessOut, int time);
// function that prints when a Process finishes a cpu burst and moves to the I/O queue
void printCPUToIO(Process myProcessOut, int time);
// funcation that prints when a Process finishes its timeslice and moves to the expired queue
void printExpiredTimeslice(Process myProcessOut, int time);
// function that prints when a Process finishes I/O burst and moves to the expired queue
void printIOToExpired(Process myProcessOut, int time);
// function that prints when a Process finishes I/O burst and moves to active queue
void printIOToActive(Process myProcessOut, int time);
// function that prints when the active and expired arrays are swapped
void printSwap(int time);
// *****************MOST CALC STATEMENTS********************************
// function that calculates Turn around time for a Process
void calcTAT(Process myProcessIn);
// fucntion that calculates Total CPU time
void calcTCT(Process myProcessIn);
// funtion that calculates Wait Time
void calcWT(Process myProcessIn);
// function that calculates percentage of CPU utilization time
void calcCUT(Process myProcessIn);
// function that calculates the average Turn around time
void calcAvgTAT();
// function that calculates the average Wait time
void calcAvgWT();
// function that calculates the average CPU utilization time
void calcAvgCUT();
*/
//***********************************
// main
//***********************************
int main() {
ProcessContents *process;
ProcessContents Startup, Active, Expired, Finished, Io, Cpu;
int numTotalBursts= 0;
// check to see if the input is specified and correct
i = 0;
// Get input from the file and load startup queue
cout << " Begin startup queue initialization " << endl;
// get the max number of Processes
cin >> maxProcesses;
process = new ProcessContents;
// Check to make sure its not the end of the file
while(cin.eof() == 0 && maxProcesses != 0) {
// give it a pid first
process -> pid = i;
i++;
cout << "pid:" << process -> pid << endl;
// get Processes nice value
cin >> process -> nice;
cout << "nice:" << process -> nice << endl;
// get Processes arrival time
cin >> process -> arrivalTime;
cout << "atime:" << process -> arrivalTime << endl;
// get Processes number of cpu bursts
cin >> process -> numCPUBursts;
cout << "#cpu bursts:" << process -> numCPUBursts << endl;
// calculate the number of io bursts ( numer of cpu bursts - 1)
process -> numIOBursts = process -> numCPUBursts - 1;
cout << "#io bursts:" << process -> numIOBursts << endl;
// get the total bursts in the process
process -> totalBursts = process -> numIOBursts + process -> numCPUBursts;
cout << "#total bursts: " << process -> totalBursts << endl;
process -> burst = new int[process -> totalBursts];
// get the cpu bursts or io bursts
for (j = process -> totalBursts - 1; j >= 0; j--) {
cin >> process -> burst[j];
cout << "Burst: " << j << " is " << process-> burst[j] << " long." << endl;
} // end of read for bursts
Startup.insert(process);
} // end of read for an entire file
cout << " Done initilizing startup queue " << endl;
for(; !Startup.isBeginning(); Startup.prev())
Startup.getData();
return 0;
}
//***********************************
// functions
//***********************************
/*
// function that prints Arrival Processes in the active queue
void printArrivalActive(Process myProcessIn) {
}
// function that prints when a Process enters the cpu
void printEnterCPU(Process myProcessIn, int time) {
}
// function that prints when a Process is preempted
void printPreempt(Process myProcessIn, Process myProcessOut, int time) {
}
//function that prints when a Process is finsihed with all cpu bursts
void printFinishCPU(Process myProcessOut, int time) {
}
// function that prints when a Process finishes a cpu burst and moves to the I/O queue
void printCPUToIO(Process myProcessOut, int time) {
}
// funcation that prints when a Process finishes its timeslice and moves to the expired queue
void printExpiredTimeslice(Process myProcessOut, int time) {
}
// function that prints when a Process finishes I/O burst and moves to the expired queue
void printIOToExpired(Process myProcessOut, int time) {
}
// function that prints when a Process finishes I/O burst and moves to active queue
void printIOToActive(Process myProcessOut, int time) {
}
// function that prints when the active and expired arrays are swapped
void printSwap(int time) {
}
// function that calculates Turn around time for a Process
void calcTAT(Process myProcessIn) [
}
// fucntion that calculates Total CPU time
void calcTCT(Process myProcessIn) {
}
// funtion that calculates Wait Time
void calcWT(Process myProcessIn) {
}
// function that calculates percentage of CPU utilization time
void calcCUT(Process myProcessIn) {
}
// function that calculates the average Turn around time
void calcAvgTAT() {
}
// function that calculates the average Wait time
void calcAvgWT() {
}
// function that calculates the average CPU utilization time
void calcAvgCUT() {
}
*/
my input file looks like:
6
0 16 3 100 100 100 100 100
-4 100 3 300 30 300 10 200
-20 200 2 12 30 300
0 25 1 300
15 50 3 340 290 582 102 10
-15 0 4 20 400 10 200 100 45 6
and my output right now currently shows the address of pointers after certain executions and is a little messy since I have been working on debugging it for awhile.
Begin startup queue initialization
pid:0
nice:0
atime:16
#cpu bursts:3
#io bursts:2
#total bursts: 5
Burst: 4 is 100 long.
Burst: 3 is 100 long.
Burst: 2 is 100 long.
Burst: 1 is 100 long.
Burst: 0 is 100 long.
POINTERS: 0xbfc5447c 0 0
PRINT PREVIOUS 0xbfc5447c
POINTERS AFTER: 0xbfc5447c 0x9360070 0
pid:1
nice:-4
atime:100
#cpu bursts:3
#io bursts:2
#total bursts: 5
Burst: 4 is 300 long.
Burst: 3 is 30 long.
Burst: 2 is 300 long.
Burst: 1 is 10 long.
Burst: 0 is 200 long.
POINTERS: 0x9360070 0x9360070 0
PRINT PREVIOUS 0x9360070
POINTERS AFTER: 0x9360070 0x9360070 0
pid:2
nice:-20
atime:200
#cpu bursts:2
#io bursts:1
#total bursts: 3
Burst: 2 is 12 long.
Burst: 1 is 30 long.
Burst: 0 is 300 long.
POINTERS: 0x93600d8 0x9360070 0
PRINT PREVIOUS 0x93600d8
POINTERS AFTER: 0x93600d8 0x9360070 0
pid:3
nice:0
atime:25
#cpu bursts:1
#io bursts:0
#total bursts: 1
Burst: 0 is 300 long.
POINTERS: 0x9360130 0x9360070 0
PRINT PREVIOUS 0x9360130
POINTERS AFTER: 0x9360130 0x9360070 0
pid:4
nice:15
atime:50
#cpu bursts:3
#io bursts:2
#total bursts: 5
Burst: 4 is 340 long.
Burst: 3 is 290 long.
Burst: 2 is 582 long.
Burst: 1 is 102 long.
Burst: 0 is 10 long.
POINTERS: 0x9360188 0x9360070 0
PRINT PREVIOUS 0x9360188
POINTERS AFTER: 0x9360188 0x9360070 0
pid:5
nice:-15
atime:0
#cpu bursts:4
#io bursts:3
#total bursts: 7
Burst: 6 is 20 long.
Burst: 5 is 400 long.
Burst: 4 is 10 long.
Burst: 3 is 200 long.
Burst: 2 is 100 long.
Burst: 1 is 45 long.
Burst: 0 is 6 long.
POINTERS: 0x93601f0 0x9360070 0
PRINT PREVIOUS 0x93601f0
POINTERS AFTER: 0x93601f0 0x9360070 0
Done initilizing startup queue
Pid: 0
Arrival time: 16
Priority: 69
Total Burst: 5
Pid: 0
Arrival time: 16
Priority: 69
Total Burst: 5
Pid: 0
Arrival time: 16
Priority: 69
Total Burst: 5
Pid: 0
Arrival time: 16
Priority: 69
Total Burst: 5
Pid: 0
Arrival time: 16
Priority: 69
Total Burst: 5
Pid: 0
Arrival time: 16
Priority: 69
Total Burst: 5