2024-10-06 15:32:20 +02:00
|
|
|
#include "queuetest.h"
|
|
|
|
|
#include "alloc.h"
|
2024-10-13 15:27:04 +02:00
|
|
|
#include "queue.h"
|
|
|
|
|
#include "testprint.h"
|
2024-10-06 15:32:20 +02:00
|
|
|
#include <stdbool.h>
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
|
|
queue *random_queue(int size, int maxval) {
|
2024-10-13 15:27:04 +02:00
|
|
|
queue* p = create_queue();
|
|
|
|
|
for (int i = 0; i < size; i++) {
|
|
|
|
|
enqueue(rand() % maxval, p);
|
|
|
|
|
// print_queue(p);
|
|
|
|
|
}
|
|
|
|
|
return p;
|
2024-10-06 15:32:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
queue *copy_queue(queue *p) {
|
2024-10-13 15:27:04 +02:00
|
|
|
queue* p_out = create_queue();
|
|
|
|
|
for (int i = 0; i < getsize_queue(p); i++) {
|
|
|
|
|
// printf("left: %d right: %d size: %d\n", p -> left, p -> right, p -> size_array);
|
|
|
|
|
int val = dequeue(p);
|
|
|
|
|
// printf("val: %d\n", val);
|
|
|
|
|
enqueue(val, p);
|
|
|
|
|
enqueue(val, p_out);
|
|
|
|
|
// print_queue(p);
|
|
|
|
|
// print_queue(p_out);
|
|
|
|
|
}
|
|
|
|
|
return p_out;
|
2024-10-06 15:32:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
queue *mountain_queue(int n) {
|
2024-10-13 15:27:04 +02:00
|
|
|
queue* p = create_queue();
|
|
|
|
|
for (int i = 0; i < n; i++) {
|
|
|
|
|
enqueue(n - i, p);
|
|
|
|
|
// print_queue(p);
|
|
|
|
|
}
|
|
|
|
|
return p;
|
2024-10-06 15:32:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void select_sort_queue(queue *p) {
|
2024-10-13 15:27:04 +02:00
|
|
|
int n = getsize_queue(p);
|
|
|
|
|
for (int i = 0; i < n; i++) {
|
|
|
|
|
int max = dequeue(p);
|
|
|
|
|
for (int j = 1; j < n - i; j++) {
|
|
|
|
|
int val = dequeue(p);
|
|
|
|
|
if (val > max) {
|
|
|
|
|
enqueue(max, p);
|
|
|
|
|
max = val;
|
|
|
|
|
} else {
|
|
|
|
|
enqueue(val, p);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
for (int j = 0; j < i; j++) {
|
|
|
|
|
enqueue(dequeue(p), p);
|
|
|
|
|
}
|
|
|
|
|
enqueue(max, p);
|
|
|
|
|
}
|
|
|
|
|
return;
|
2024-10-06 15:32:20 +02:00
|
|
|
}
|