add queue
This commit is contained in:
7
examples/hashmap/hm1.c
Normal file
7
examples/hashmap/hm1.c
Normal file
@@ -0,0 +1,7 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main(void) {
|
||||
puts("TODO: Hashmap");
|
||||
|
||||
return 0;
|
||||
}
|
||||
53
examples/queue/q1.c
Normal file
53
examples/queue/q1.c
Normal file
@@ -0,0 +1,53 @@
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "../../queue/myqueue.h"
|
||||
|
||||
int main(void) {
|
||||
mcl_queue *queue = mcl_queue_init(3, sizeof(int));
|
||||
assert(queue != NULL);
|
||||
|
||||
int val, out;
|
||||
|
||||
val = 1;
|
||||
assert(mcl_queue_push(queue, &val) == 0);
|
||||
|
||||
val = 2;
|
||||
assert(mcl_queue_push(queue, &val) == 0);
|
||||
|
||||
int front = *((int *)mcl_queue_get_front(queue));
|
||||
int rear = *((int *)mcl_queue_get_rear(queue));
|
||||
printf("Front: %d, Rear: %d\n", front, rear);
|
||||
assert(front == 1);
|
||||
assert(rear == 2);
|
||||
|
||||
assert(mcl_queue_pop(queue, &out) == 0);
|
||||
printf("Pop: %d\n", out);
|
||||
assert(out == 1);
|
||||
|
||||
front = *((int *)mcl_queue_get_front(queue));
|
||||
printf("Front after pop: %d\n", front);
|
||||
assert(front == 2);
|
||||
|
||||
val = 3;
|
||||
assert(mcl_queue_push(queue, &val) == 0);
|
||||
|
||||
rear = *((int *)mcl_queue_get_rear(queue));
|
||||
printf("Rear after push 3: %d\n", rear);
|
||||
assert(rear == 3);
|
||||
|
||||
val = 4;
|
||||
int res = mcl_queue_push(queue, &val);
|
||||
assert(res == 0);
|
||||
|
||||
while (mcl_queue_pop(queue, &out) == 0) {
|
||||
printf("Pop: %d\n", out);
|
||||
}
|
||||
printf("Queue is now empty\n");
|
||||
|
||||
assert(mcl_queue_pop(queue, &out) == -1);
|
||||
|
||||
mcl_queue_free(queue);
|
||||
printf("All tests passed successfully.\n");
|
||||
return 0;
|
||||
}
|
||||
24
examples/string/str1.c
Normal file
24
examples/string/str1.c
Normal file
@@ -0,0 +1,24 @@
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "../../string/mystring.h"
|
||||
|
||||
int main(void) {
|
||||
mcl_string *str = mcl_string_new("Hello, world!", 512);
|
||||
assert(str != NULL);
|
||||
|
||||
printf("%s\nsize: %ld, cap: %ld\n", mcl_string_cstr(str), (long)mcl_string_length(str), (long)mcl_string_capacity(str));
|
||||
assert(mcl_string_length(str) == 13);
|
||||
|
||||
int ret = mcl_string_append(str, " How are you?");
|
||||
assert(ret == 0);
|
||||
|
||||
printf("After append:\n");
|
||||
printf("%s\nsize: %ld, cap: %ld\n", mcl_string_cstr(str), (long)mcl_string_length(str), (long)mcl_string_capacity(str));
|
||||
assert(mcl_string_length(str) == 26);
|
||||
|
||||
mcl_string_free(str);
|
||||
|
||||
printf("All tests passed successfully.\n");
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user