Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "linkedListArray.h"
- void Create(Node **queue)
- {
- for (int i = 0; i < MAXPRI; i++) {
- queue[i] = NULL;
- }
- }
- void Push(Node **queue, int pri, int id)
- {
- Node *new_node = malloc(sizeof(Node));
- if (new_node != NULL) {
- new_node->id = id;
- new_node->next = NULL;
- if (queue[pri] == NULL) {
- queue[pri] = new_node;
- }
- else {
- Node *aux = queue[pri];
- while (aux->next != NULL) {
- aux = aux->next;
- }
- aux->next = new_node;
- }
- }
- }
- void Execute(Node **queue)
- {
- bool end = false;
- int i = 0;
- while (!end && i < MAXPRI) {
- if (queue[i] != NULL) {
- Node *aux = queue[i];
- queue[i] = queue[i]->next;
- free(aux);
- end = true;
- }
- i++;
- }
- if (!end) {
- printf("There are no processes\n");
- }
- }
- int Search(Node **queue, unsigned int id)
- {
- int pri = -1;
- Node *aux;
- for (int i = 0; i < MAXPRI && pri == -1; ++i) {
- aux = queue[i];
- while (aux != NULL && pri == -1) {
- if (aux->id == id) {
- pri = i;
- }
- else
- aux = aux->next;
- }
- }
- return pri;
- }
- void Output(Node *head)
- {
- for (Node *current = head; current != NULL; current = current->next) {
- if (current->next != NULL)
- printf ("%d -> ", current->id);
- else
- printf ("%d", current->id);
- }
- }
- void Display(Node **queue)
- {
- for (int i = 0; i < MAXPRI; i++) {
- printf ("Priority queue %d: ", i);
- Output(queue[i]);
- putchar('\n');
- }
- putchar('\n');
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement