please help

So the process are arriving correctly, 1, 2, 3, 4....., the process are terminating 4, 3, 2, 1, 0 , -1, -2.... but I need it to stop when it gets to 1 and give error, until another process such as 5 arrives. Some please help how to do this.


this is my main file:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
int main(){
	ready_queue rq;
	int pid = 0;
	
	while (true){
	    char input;
	    cout << ">>> ";
	    cin >> input;
	    
	switch (input){
		case 'A':
          rq.process_arrival(pid);
		  pid++;		
		  cout << "A process with PID " << pid << " has arrived" <<endl<<endl;
		  break;
		case 't':
		  rq.process_terminate(pid);
		  cout << "A process with PID " << pid << " has died" <<endl<<endl;
		  pid--;
		  break;
    }
  }
}


this is my .h file:
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
class PCB{
	public:
	  PCB *next;
	  int pid;
};

class ready_queue{
	private:
	   PCB *head;
	   PCB *tail;   	
	public: 
	   void process_arrival(int pid);
	   void process_terminate(int pid);
};

void ready_queue :: process_arrival(int pid){
	PCB *temp = new PCB();
	temp->pid = pid; 
	temp->next=NULL;
	if (head = NULL){
		head = temp;
	}
	else if (head != NULL){
		tail ->next = temp;
	}
	tail = temp;
}

void ready_queue :: process_terminate(int pid){
     if (head != NULL){
     	PCB*temp = head;
     	head = head->next;
     	temp->next = NULL;
        delete temp;     	
 }
}
urgent help please!
so they arrive 1,2,3,4,5.
How can I make them terminate 1,2,3,4,5 and then print error, until next one arrives? How to do this using my process_arrive & process_terminate functions?
Topic archived. No new replies allowed.