Function renaming and moving.
This commit is contained in:
6 files changed
+48
-47
No files matched your search
+23
-23
@@ -2,41 +2,41 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
static Node* q_front = NULL;
|
||||
static Node* q_back = NULL;
|
||||
static Node* queue_front = NULL;
|
||||
static Node* queue_back = NULL;
|
||||
static int current_size = 0;
|
||||
static int capacity = 0;
|
||||
|
||||
void q_init(int max_elements) {
|
||||
void queue_init(int max_elements) {
|
||||
capacity = max_elements;
|
||||
q_front = NULL;
|
||||
q_back = NULL;
|
||||
queue_front = NULL;
|
||||
queue_back = NULL;
|
||||
current_size = 0;
|
||||
}
|
||||
|
||||
void q_push(Node* n) {
|
||||
void queue_push(Node* n) {
|
||||
if (current_size >= capacity) return; /* Pool safety */
|
||||
|
||||
/* Exact logic from your 'enqueue' function */
|
||||
n->next = NULL;
|
||||
if (!q_back) {
|
||||
q_front = q_back = n;
|
||||
if (!queue_back) {
|
||||
queue_front = queue_back = n;
|
||||
} else {
|
||||
q_back->next = n;
|
||||
q_back = n;
|
||||
queue_back->next = n;
|
||||
queue_back = n;
|
||||
}
|
||||
current_size++;
|
||||
}
|
||||
|
||||
Node* q_pop() {
|
||||
Node* queue_pop() {
|
||||
/* Exact logic from your 'dequeue' function */
|
||||
if (!q_front) return NULL;
|
||||
if (!queue_front) return NULL;
|
||||
|
||||
Node* r = q_front;
|
||||
q_front = q_front->next;
|
||||
Node* r = queue_front;
|
||||
queue_front = queue_front->next;
|
||||
|
||||
if (!q_front) {
|
||||
q_back = NULL;
|
||||
if (!queue_front) {
|
||||
queue_back = NULL;
|
||||
}
|
||||
|
||||
r->next = NULL; /* Clean up the link */
|
||||
@@ -45,19 +45,19 @@ Node* q_pop() {
|
||||
return r;
|
||||
}
|
||||
|
||||
int q_size() {
|
||||
int queue_size() {
|
||||
return current_size;
|
||||
}
|
||||
|
||||
void q_clear() {
|
||||
q_front = NULL;
|
||||
q_back = NULL;
|
||||
void queue_clear() {
|
||||
queue_front = NULL;
|
||||
queue_back = NULL;
|
||||
current_size = 0;
|
||||
}
|
||||
|
||||
void q_destroy() {
|
||||
q_front = NULL;
|
||||
q_back = NULL;
|
||||
void queue_destroy() {
|
||||
queue_front = NULL;
|
||||
queue_back = NULL;
|
||||
current_size = 0;
|
||||
capacity = 0;
|
||||
}
|
||||
Reference in new issue
Block a user