so.hpp
#ifndef so_hpp
#define so_hpp
#include <iostream>
#include <assert.h>
class process {
class node {
char _id;
int _time;
int _priority;
node *_next;
public:
node(char i, int t, int q);
char id() const { return _id; } //cual es el id
int tme() const { return _time; } //cual es el tiempo
int prty() const { return _priority; } //cual es la prioridad
node *next() const { return _next; } // cual es el siguiente apuntador
void next(node *p) { _next = p; } // cambia el siguiente ap
};
int n; // Capacity of process
int s; // Size of process
node *head; // First item in queue
node *tail; // Last item in queue
public:
process(int);
~process();
void push(int);
int pop(void);
int capacity() const { return n; }
int size() const { return s; }
bool full() const { return s==n; }
bool empty() const { return s==0; }
void print();
};
#endif /* so_hpp */
so.cpp
#include "so.hpp"
process::node::node(char i, int t, int q) {
_id = i;
_time = t;
_priority = q;
_next = nullptr;
}
process::process(int c){
n = c;
s = 0;
head = nullptr;
tail = nullptr;
}
process::~process(){
while(head != nullptr) {
node *p = head;
head = head -> next();
delete p;
}
}
void process::push(char i, int t, int q){
assert(!full());
node *p = new node(i, t, q);
if(empty()) {
head = p;
tail = p;
}else{
tail -> next(p);
tail = p;
}
s++;
}
int process::pop(){
assert(!empty());
char i = head -> id();
int t = head -> tme();
int q = head -> prty();
node *p = head;
head = p -> next();
delete p;
s--;
return x;
}
void process::print(){
node *p = head;
std::cout<<"[ ";
while(p != nullptr){
std::cout << p -> data() << " ";
p = p -> next();
}
std::cout << "]" << std::endl;
}
Top comments (0)