void LL::decrement(int NewNum)
{
int id;
int temp;
int temp2;
Process *x = front;
if(x->id != 1)
{
while(x!= NULL)
{
x->id = temp; // puts the current id to temp
temp2 = temp-1; //temp2 gets decremented by 1
temp2 = NewNum;
x = x->next;// gets next value
}
}
}
The logic of this code seems wrong for what you are trying to do...
1 2 3 4 5 6 7 8
x->id = temp; // puts the current id to temp --- temp is a unknown value when it hits here.
// it isn't passed in and it isn't set to some value in the function.
temp2 = temp-1; //temp2 gets decremented by 1
// temp2 will always be temp -1, which I expect temp to be 0 or some random value
temp2 = NewNum; // after the above value is set for temp2 you reset it to New Num which is passed in.
x = x->next;// gets next value
I don't know if that is going to point you in a direction or not. I don't know if id, temp, and temp2 are suppose to be members of the LL class or not or are suppose to be local to this function.
struct Process
{
int id; // id for the class.. this wouldn't change
STATE myState;
double temp; // the stored temp.
Process *next;
};
// in the loop.
void LL:: decrement(int NewNum)
{
Process *x = front;
while(x!=NULL)
{
if(x->id != 1) // assuming this is a special state of some form.
{
x->temp-=1;
}
}
}
q1.insert(arr[4].id) // when i call this function it inserts 5 to the id in the array Process,
q1.insert(arr[5].id)// when i call this function it outputs 6 to the id in the array Process
q1.display() // this displays the queue
q1.decrement() // this should decrement all values of id by 1
q1.display() // this should display the queue after the values of id have decreased by one
void LL:: decrement(int NewNum)
{
Process *x = front;
while(x!=NULL)
{
x->id-=1; // this would decrement the id by one.
// if I needed to preform a bounds check I would do it here.
// like if the id fell to 0;
x = x->next;
}
// this still leaves NewNum unused here.
// and I still haven't used temp and temp2, which have no purpose in what you are asking for.
}